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

ErrorHandler#harshly no longer fails when backtrace nil #229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/makara/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def gracefully(connection, e)


def harshly(e)
::Makara::Logging::Logger.log("Harshly handling: #{e}\n#{e.backtrace.join("\n\t")}")
::Makara::Logging::Logger.log("Harshly handling: #{e}\n#{e.backtrace&.join("\n\t")}")
raise e
end

Expand Down
38 changes: 38 additions & 0 deletions spec/error_handler_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require "spec_helper"

describe Makara::ErrorHandler do
let(:handler){ described_class.new }

before{ allow(::Makara::Logging::Logger).to receive(:log) }

describe "#harshly" do
subject{ handler.send(:harshly, error) }

context "an error with a backtrace" do
let(:error){ StandardError.new }

before do
error.set_backtrace(caller)
expect(error.backtrace).not_to be_nil
end

it "re-raises the original exception and logs with a backtrace" do
expect{ subject }.to raise_error(error)
expect(::Makara::Logging::Logger).to have_received(:log).with(/Harshly handling: StandardError\s+.+/i)
end
end

context "an error without a backtrace" do
let(:error){ StandardError.new }

before { expect(error.backtrace).to be_nil }

it "re-raises the original exception and logs without a backtrace" do
expect{ subject }.to raise_error(error)
expect(::Makara::Logging::Logger).to have_received(:log).with("Harshly handling: StandardError\n")
end

end
end

end