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

Preserve exception backtrace in case of Surrealist::UndefinedMethodError #122

Merged
merged 2 commits into from
Oct 12, 2018
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
3 changes: 2 additions & 1 deletion lib/surrealist/exception_raiser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def raise_invalid_root!(value)
def raise_invalid_key!(err)
raise Surrealist::UndefinedMethodError,
"#{err.message}. You have probably defined a key " \
"in the schema that doesn't have a corresponding method."
"in the schema that doesn't have a corresponding method.",
err.backtrace
end

# Raises ArgumentError if a tag has no corresponding serializer
Expand Down
24 changes: 24 additions & 0 deletions spec/exception_raiser_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

RSpec.describe Surrealist::ExceptionRaiser do
describe '.raise_invalid_key!' do
let(:backtrace) { %w[a b c] }

it 'preserves exception backtrace and displays correct message' do
begin
raise NoMethodError, 'my error message', backtrace
rescue NoMethodError => e
begin
described_class.raise_invalid_key!(e)
rescue Surrealist::UndefinedMethodError => e
expect(e.message).to eq(
"my error message. " \
"You have probably defined a key " \
"in the schema that doesn't have a corresponding method.",
)
expect(e.backtrace).to eq(backtrace)
end
end
end
end
end