Skip to content

Commit

Permalink
Merge pull request #71 from mnemosyne-mon/fix/action-dispatch-excepti…
Browse files Browse the repository at this point in the history
…on-wrapper

fix: Invalid exception class for ActionDispatch::ExceptionWrapper
  • Loading branch information
jgraichen authored Nov 27, 2023
2 parents 853eba2 + b849f8f commit 2001bb1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- Add testing for Rails 7.1 by @MrSerth

### Fixed

- Invalid exception class for ActionDispatch::ExceptionWrapper by @jgraichen

## [1.16.0] - 2023-08-24

### Added
Expand Down
7 changes: 6 additions & 1 deletion lib/mnemosyne/probes/action_dispatch/show_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ def setup
module Instrumentation
def render_exception(env, exception)
if (trace = ::Mnemosyne::Instrumenter.current_trace)
trace.attach_error(exception)
if exception.respond_to?(:unwrapped_exception) && exception.respond_to?(:exception)
# ActionDispatch::ExceptionWrapper
trace.attach_error(exception.exception)
else
trace.attach_error(exception)
end
end

super
Expand Down
36 changes: 36 additions & 0 deletions spec/mnemosyne/probes/action_dispatch/show_exceptions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require 'spec_helper'
require 'action_dispatch'
require 'action_view'

RSpec.describe Mnemosyne::Probes::ActionDispatch::ShowExceptions::Probe, probe: :rails do
let(:exception_application) do
->(_env) { [200, {}, ''] }
end

let(:application) do
raise_error = -> { raise error }
exception_application = self.exception_application

Rack::Builder.app do
use ActionDispatch::ShowExceptions, exception_application
run ->(_env) { raise_error.call }
end
end

let(:mock) { Rack::MockRequest.new(application) }
let(:error) { RuntimeError.new('ABC') }

it 'attaches an exception' do
trace = with_trace do
mock.request
end

expect(trace.errors.size).to eq 1

trace.errors.first.tap do |record|
expect(record.error).to be error
end
end
end

0 comments on commit 2001bb1

Please sign in to comment.