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

closes #964 Improve error message for packet mutex breaking marshal dump #967

Merged
3 commits merged into from
Apr 2, 2019
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
5 changes: 5 additions & 0 deletions lib/cosmos/top_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ def self.marshal_dump(marshal_filename, obj)
rescue Exception
# Oh well - we tried
end
if exception.class == TypeError and exception.message =~ /Thread::Mutex/
original_backtrace = exception.backtrace
exception = exception.exception("Mutex exists in a packet. Note: Packets must not be read during class initializers for Conversions, Limits Responses, etc.: #{exception}")
exception.set_backtrace(original_backtrace)
end
self.handle_fatal_exception(exception)
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/top_level/top_level_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ def self.cleanup_exceptions
Cosmos.cleanup_exceptions()
end

it "rescues marshal dump errors in a Packet with a Mutex" do
capture_io do |stdout|
system_exit_count = $system_exit_count
pkt = Packet.new("TGT","PKT")
pkt.append_item("ITEM", 16, :UINT)
pkt.read_all
Cosmos.marshal_dump('marshal_test', pkt)
expect($system_exit_count).to be > system_exit_count
expect(stdout.string).to match("Mutex exists in a packet")
end
Cosmos.cleanup_exceptions()
end

it "rescues marshal load errors" do
# Attempt to load something that doesn't exist
expect(Cosmos.marshal_load('blah')).to be_nil
Expand Down