Skip to content

Commit

Permalink
ErrorHandler#harshly no longer fails when backtrace nil
Browse files Browse the repository at this point in the history
  • Loading branch information
Raph Estrada committed Mar 8, 2019
1 parent 01195ef commit ddd2424
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
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
39 changes: 39 additions & 0 deletions spec/error_handler_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'spec_helper'
require 'time'

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 "sends a metric, 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

0 comments on commit ddd2424

Please sign in to comment.