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

Fix DRbUnknown error with unserializable Exception causes #79

Merged
merged 1 commit into from
Feb 29, 2024
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
4 changes: 2 additions & 2 deletions lib/flatware/serialized_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ class SerializedException
attr_reader :class, :message, :cause
attr_accessor :backtrace

def initialize(klass, message, backtrace, cause = '')
def initialize(klass, message, backtrace, cause = nil)
@class = serialized(klass)
@message = message
@backtrace = backtrace
@cause = cause
@cause = cause && SerializedException.from(cause)
end

def self.from(exception)
Expand Down
29 changes: 24 additions & 5 deletions spec/flatware/rspec/marshalable/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def stub_execution_result(exception)
)
end

it 'caries what is needed to format a backtrace' do
it 'carries what is needed to format a backtrace' do
exception = Exception.new
RSpec::Core::Formatters::ExceptionPresenter.new(
exception,
Expand All @@ -29,20 +29,39 @@ def stub_execution_result(exception)
).fully_formatted(nil)
end

it 'does not cary constant references in exceptions' do
it 'does not carry constant references in exceptions' do
const = stub_const('A::Constant::Not::Likely::Loaded::In::Sink', Class.new(RuntimeError))
wrapper_const = stub_const('Another::Constant::Not::Likely::Loaded::In::Sink', Class.new(RuntimeError))
caught_exception = begin
begin
raise const, 'something bad happened'
rescue RuntimeError => e
# raise a second exception so that Exception#cause is set up
raise wrapper_const, e
end
rescue RuntimeError => e
e
end

message = described_class.new(
instance_double(
RSpec::Core::Example,
execution_result: stub_execution_result(const.new),
execution_result: stub_execution_result(caught_exception),
full_description: nil,
location: nil,
location_rerun_argument: nil,
metadata: {}
)
)

expect(message.execution_result.exception.class.to_s).to eq(const.to_s)
expect(message.execution_result.exception.class).to_not be_an_instance_of(const)
result_exception = message.execution_result.exception

expect(result_exception).to be_an_instance_of(Flatware::SerializedException)
expect(result_exception.class.to_s).to eq(wrapper_const.to_s)
expect(result_exception.class).to_not be_an_instance_of(wrapper_const)

expect(result_exception.cause).to be_an_instance_of(Flatware::SerializedException)
expect(result_exception.cause.class.to_s).to eq(const.to_s)
expect(result_exception.cause.class).to_not be_an_instance_of(const)
end
end