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

Add original_error to Report/Event #692

Merged
merged 2 commits into from
Sep 8, 2021
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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Changelog
| [#690](https://github.com/bugsnag/bugsnag-ruby/pull/690)
* Add `errors` to `Report`/`Event` containing an array of `Error` objects. The `Error` object contains `error_class`, `error_message` and `type` (always "ruby")
| [#691](https://github.com/bugsnag/bugsnag-ruby/pull/691)
* Add `original_error` to `Report`/`Event` containing the original Exception instance
| [#692](https://github.com/bugsnag/bugsnag-ruby/pull/692)

### Fixes

Expand All @@ -40,6 +42,7 @@ Changelog
* The breadcrumb type constants in the `Bugsnag::Breadcrumbs` module has been deprecated in favour of the constants available in the `Bugsnag::BreadcrumbType` module
For example, `Bugsnag::Breadcrumbs::ERROR_BREADCRUMB_TYPE` is now available as `Bugsnag::BreadcrumbType::ERROR`
* `Report#exceptions` has been deprecated in favour of the new `errors` property
* `Report#raw_exceptions` has been deprecated in favour of the new `original_error` property

## v6.22.1 (11 August 2021)

Expand Down
6 changes: 6 additions & 0 deletions lib/bugsnag/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Report
attr_accessor :meta_data

# The raw Exception instances for this report
# @deprecated Use {#original_error} instead
# @see #exceptions
# @return [Array<Exception>]
attr_accessor :raw_exceptions
Expand Down Expand Up @@ -109,6 +110,10 @@ class Report
# @return [Array<Error>]
attr_reader :errors

# The Exception instance this report was created for
# @return [Exception]
attr_reader :original_error

##
# Initializes a new report from an exception.
def initialize(exception, passed_configuration, auto_notify=false)
Expand All @@ -120,6 +125,7 @@ def initialize(exception, passed_configuration, auto_notify=false)

self.configuration = passed_configuration

@original_error = exception
self.raw_exceptions = generate_raw_exceptions(exception)
self.exceptions = generate_exception_list
@errors = generate_error_list
Expand Down
7 changes: 7 additions & 0 deletions spec/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ def gloops
)
end
end

it "has a reference to the original error" do
exception = RuntimeError.new("example error")
report = class_to_test.new(exception, Bugsnag.configuration)

expect(report.original_error).to be(exception)
end
end

# rubocop:disable Metrics/BlockLength
Expand Down