Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workaround for rails infected error classes #1216

Merged
merged 1 commit into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# Unreleased
# v0.10.27 2021-02-02

* [#1216](https://github.com/mbj/mutant/pull/1216)

Fix exception serialization form rails infected code bases.
This case can happen when the killfork terminates abnormal,
and the resulting exception in the worker has to be propagated to
the main process for reporting.
On "normal" Ruby the exceptions are dump/loadable but rails and
its core extensions break this invariant. Hence mutant now
captures the essence of the exception in an attribute copy for
propagation.

* [#1207](https://github.com/mbj/mutant/pull/1207)

* Remove `#eql?` -> `#equal?` mutation

* [#1210](https://github.com/mbj/mutant/pull/1210)

* Remove generic mutation to `self`

# v0.10.26 2021-01-16
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
mutant (0.10.26)
mutant (0.10.27)
diff-lcs (~> 1.3)
parser (~> 3.0.0)
regexp_parser (~> 2.0, >= 2.0.3)
Expand Down
3 changes: 2 additions & 1 deletion lib/mutant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ module Mutant
require 'mutant/ast/meta/resbody'
require 'mutant/parser'
require 'mutant/isolation'
require 'mutant/isolation/none'
require 'mutant/isolation/exception'
require 'mutant/isolation/fork'
require 'mutant/isolation/none'
require 'mutant/parallel'
require 'mutant/parallel/driver'
require 'mutant/parallel/source'
Expand Down
22 changes: 22 additions & 0 deletions lib/mutant/isolation/exception.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Mutant
# Module providing isolation
class Isolation
# Generic serializable exception data.
#
# This is required as our honored guests the Rails* ecosystem
# makes Marshal.dump on exceptions impossible.
#
# @see https://twitter.com/_m_b_j_/status/1356433184850907137
#
# for the full story and eventual reactions.
class Exception
include Anima.new(
:backtrace,
:message,
:original_class
)
end # Exception
end # Isolation
end # Mutant
6 changes: 5 additions & 1 deletion lib/mutant/isolation/fork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ def read_child_result
def load_result(result_fragments)
@value = world.marshal.load(result_fragments.join)
rescue ArgumentError => exception
@exception = exception
@exception = Exception.new(
backtrace: exception.backtrace,
message: exception.message,
original_class: exception.class
)
end

# rubocop:disable Metrics/MethodLength
Expand Down
4 changes: 3 additions & 1 deletion lib/mutant/reporter/cli/printer/isolation_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class IsolationResult < self
```
%s
%s
%s
```
MESSAGE

Expand Down Expand Up @@ -81,7 +82,8 @@ def print_exception

puts(
EXCEPTION_ERROR_MESSAGE % [
exception.inspect,
exception.original_class,
exception.message,
exception.backtrace.join("\n")
]
)
Expand Down
2 changes: 1 addition & 1 deletion lib/mutant/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

module Mutant
# Current mutant version
VERSION = '0.10.26'
VERSION = '0.10.27'
end # Mutant
6 changes: 5 additions & 1 deletion spec/unit/mutant/isolation/fork_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,11 @@ def timer(now)
expect(apply).to eql(
described_class::Result.new(
log: log_fragment,
exception: exception,
exception: Mutant::Isolation::Exception.new(
backtrace: exception.backtrace,
message: exception.message,
original_class: exception.class
),
process_status: child_status_success,
timeout: nil,
value: nil
Expand Down
17 changes: 7 additions & 10 deletions spec/unit/mutant/reporter/cli/printer/isolation_result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@

context 'on exception isolation error' do
let(:exception) do
Class.new(RuntimeError) do
def inspect
'<TestException>'
end

def backtrace
%w[first last]
end
end.new('foo')
Mutant::Isolation::Exception.new(
backtrace: %w[first last],
message: 'Some Exception Message',
original_class: ArgumentError
)
end

it_reports <<~'STR'
Expand All @@ -51,7 +47,8 @@ def backtrace
The following exception was raised while reading the killfork result:

```
<TestException>
ArgumentError
Some Exception Message
first
last
```
Expand Down