Skip to content

Commit

Permalink
Assert against in-project frames only
Browse files Browse the repository at this point in the history
Ruby 3.3 adds additional frames to the top of the stacktrace so frame 0
is no longer the frame we want to assert against
  • Loading branch information
imjoehaines committed Jan 4, 2024
1 parent 5020b79 commit ae1d518
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 13 deletions.
3 changes: 2 additions & 1 deletion features/fixtures/plain/app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def configure_basics
Bugsnag.configure do |conf|
conf.api_key = ENV['BUGSNAG_API_KEY']
conf.set_endpoints(ENV['BUGSNAG_ENDPOINT'], ENV["BUGSNAG_ENDPOINT"])
conf.project_root = __dir__
end
end

Expand All @@ -17,7 +18,7 @@ def configure_using_environment
conf.ignore_classes << lambda { |ex| ex.class.to_s == ENV["BUGSNAG_IGNORE_CLASS"] } if ENV.include? "BUGSNAG_IGNORE_CLASS"
conf.meta_data_filters << ENV["BUGSNAG_META_DATA_FILTERS"] if ENV.include? "BUGSNAG_META_DATA_FILTERS"
conf.enabled_release_stages = [ENV["BUGSNAG_NOTIFY_RELEASE_STAGE"]] if ENV.include? "BUGSNAG_NOTIFY_RELEASE_STAGE"
conf.project_root = ENV["BUGSNAG_PROJECT_ROOT"] if ENV.include? "BUGSNAG_PROJECT_ROOT"
conf.project_root = __dir__
conf.proxy_host = ENV["BUGSNAG_PROXY_HOST"] if ENV.include? "BUGSNAG_PROXY_HOST"
conf.proxy_password = ENV["BUGSNAG_PROXY_PASSWORD"] if ENV.include? "BUGSNAG_PROXY_PASSWORD"
conf.proxy_port = ENV["BUGSNAG_PROXY_PORT"] if ENV.include? "BUGSNAG_PROXY_PORT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

callback = Proc.new do |report|
report.exceptions[0][:stacktrace].each_with_index do |frame, index|
if index > 0
if index == 0
frame[:inProject] = nil
else
frame[:inProject] = true
end
end
end

run(callback)
run(callback)
6 changes: 3 additions & 3 deletions features/plain_features/handled_errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Scenario: A rescued exception sends a report
And the event "severityReason.type" equals "handledException"
And the event "device.time" is a timestamp
And the exception "errorClass" equals "RuntimeError"
And the "file" of stack frame 0 equals "/usr/src/app/handled/notify_exception.rb"
And the "file" of stack frame 0 equals "handled/notify_exception.rb"
And the "lineNumber" of stack frame 0 equals 6

Scenario: A notified string sends a report
Expand All @@ -21,7 +21,7 @@ Scenario: A notified string sends a report
And the event "severityReason.type" equals "handledException"
And the event "device.time" is a timestamp
And the exception "errorClass" equals "RuntimeError"
And the "file" of the top non-bugsnag stackframe equals "/usr/src/app/handled/notify_string.rb"
And the "file" of the top non-bugsnag stackframe equals "handled/notify_string.rb"
And the "lineNumber" of the top non-bugsnag stackframe equals 8

Scenario: A handled error doesn't send a report when the :skip_bugsnag flag is set
Expand All @@ -36,7 +36,7 @@ Scenario: A handled error can attach metadata in a block
And the event "severity" equals "warning"
And the event "severityReason.type" equals "handledException"
And the exception "errorClass" equals "RuntimeError"
And the "file" of stack frame 0 equals "/usr/src/app/handled/block_metadata.rb"
And the "file" of stack frame 0 equals "handled/block_metadata.rb"
And the "lineNumber" of stack frame 0 equals 6
And the event "metaData.account.id" equals "1234abcd"
And the event "metaData.account.name" equals "Acme Co"
Expand Down
2 changes: 1 addition & 1 deletion features/plain_features/release_stages.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Scenario: Does notify in the correct release stage
And the event "severity" equals "error"
And the event "severityReason.type" equals "unhandledException"
And the exception "errorClass" equals "RuntimeError"
And the "file" of stack frame 0 equals "/usr/src/app/configuration/send_unhandled.rb"
And the "file" of stack frame 0 equals "configuration/send_unhandled.rb"
8 changes: 4 additions & 4 deletions features/plain_features/report_stack_frames.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Scenario Outline: Stack frames can be removed
When I run the service "plain-ruby" with the command "bundle exec ruby stack_frame_modification/remove_stack_frame.rb"
And I wait to receive an error
Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier
And the "file" of the top non-bugsnag stackframe equals "/usr/src/app/stack_frame_modification/initiators/<initiator>.rb"
And the "file" of the top non-bugsnag stackframe equals "stack_frame_modification/initiators/<initiator>.rb"
And the "lineNumber" of stack frame 0 equals <lineNumber>

Examples:
Expand All @@ -20,15 +20,15 @@ Scenario: Stack frames can be removed from a notified string
When I run the service "plain-ruby" with the command "bundle exec ruby stack_frame_modification/remove_stack_frame.rb"
And I wait to receive an error
Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier
And the "file" of the top non-bugsnag stackframe equals "/usr/src/app/stack_frame_modification/initiators/handled_block.rb"
And the "file" of the top non-bugsnag stackframe equals "stack_frame_modification/initiators/handled_block.rb"
And the "lineNumber" of the top non-bugsnag stackframe equals 19

Scenario Outline: Stack frames can be marked as in project
Given I set environment variable "CALLBACK_INITIATOR" to "<initiator>"
When I run the service "plain-ruby" with the command "bundle exec ruby stack_frame_modification/mark_frames_in_project.rb"
And I wait to receive an error
Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier
And the "file" of stack frame 0 equals "/usr/src/app/stack_frame_modification/initiators/<initiator>.rb"
And the "file" of stack frame 0 equals "stack_frame_modification/initiators/<initiator>.rb"
And the event "exceptions.0.stacktrace.0.inProject" is null
And the event "exceptions.0.stacktrace.1.inProject" is true
And the event "exceptions.0.stacktrace.2.inProject" is true
Expand All @@ -46,7 +46,7 @@ Scenario: Stack frames can be marked as in project with a handled string
And I run the service "plain-ruby" with the command "bundle exec ruby stack_frame_modification/mark_frames_in_project.rb"
And I wait to receive an error
Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier
And the "file" of the top non-bugsnag stackframe equals "/usr/src/app/stack_frame_modification/initiators/handled_block.rb"
And the "file" of the top non-bugsnag stackframe equals "stack_frame_modification/initiators/handled_block.rb"
And the event "exceptions.0.stacktrace.0.inProject" is null
And the event "exceptions.0.stacktrace.1.inProject" is true
And the event "exceptions.0.stacktrace.2.inProject" is true
Expand Down
4 changes: 2 additions & 2 deletions features/plain_features/unhandled_errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Scenario Outline: An unhandled error sends a report
And the event "severityReason.type" equals "unhandledException"
And the event "device.time" is a timestamp
And the exception "errorClass" equals "<error>"
And the "file" of stack frame 0 equals "/usr/src/app/unhandled/<file>.rb"
And the "lineNumber" of stack frame 0 equals <lineNumber>
And the "file" of the first in-project stack frame equals "unhandled/<file>.rb"
And the "lineNumber" of the first in-project stack frame equals <lineNumber>

Examples:
| file | error | lineNumber | command |
Expand Down
15 changes: 15 additions & 0 deletions features/steps/ruby_notifier_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
}
end

Then(/^the "(.+)" of the first in-project stack frame equals (\d+|".+")$/) do |key, expected|
body = Maze::Server.errors.current[:body]
stacktrace = Maze::Helper.read_key_path(body, 'events.0.exceptions.0.stacktrace')

frame_index = stacktrace.find_index { |frame| frame["inProject"] == true }

if frame_index.nil?
raise "Unable to find an in-project stack frame in stacktrace: #{stacktrace.inspect}"
end

steps %Q{
the "#{key}" of stack frame #{frame_index} equals #{expected}
}
end

Then(/^the total sessionStarted count equals (\d+)$/) do |value|
body = Maze::Server.sessions.current[:body]
session_counts = Maze::Helper.read_key_path(body, "sessionCounts")
Expand Down

0 comments on commit ae1d518

Please sign in to comment.