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

Mark Bugsnag frames as out of project #497

Merged
merged 14 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from 6 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: 1 addition & 2 deletions lib/bugsnag/stacktrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def initialize(backtrace, configuration)

# Parse the stacktrace line

# Skip stacktrace lines inside lib/bugsnag
next(nil) if file.nil? || file =~ %r{lib/bugsnag(/|\.rb)}
next(nil) if file.nil?

# Expand relative paths
p = Pathname.new(file)
Expand Down
35 changes: 27 additions & 8 deletions spec/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,12 @@ def gloops

it "does not mark the top-most stacktrace line as inProject if out of project" do
Bugsnag.configuration.project_root = "/Random/location/here"
Bugsnag.notify(BugsnagTestException.new("It crashed"))

begin
"Test".prepnd "T"
rescue Exception => e
Bugsnag.notify(e)
end

expect(Bugsnag).to have_sent_notification{ |payload, headers|
exception = get_exception_from_payload(payload)
Expand All @@ -514,12 +519,17 @@ def gloops

it "marks the top-most stacktrace line as inProject if necessary" do
Bugsnag.configuration.project_root = File.expand_path File.dirname(__FILE__)
Bugsnag.notify(BugsnagTestException.new("It crashed"))

begin
"Test".prepnd "T"
rescue Exception => e
Bugsnag.notify(e)
end

expect(Bugsnag).to have_sent_notification{ |payload, headers|
exception = get_exception_from_payload(payload)
expect(exception["stacktrace"].size).to be >= 1
expect(exception["stacktrace"].first["inProject"]).to eq(true)
expect(exception["stacktrace"][0]["inProject"]).to eq(true)
}
end

Expand Down Expand Up @@ -1050,12 +1060,21 @@ def gloops
exception = event["exceptions"][0]
expect(exception["errorClass"]).to eq("RuntimeError")
expect(exception["message"]).to eq("'nil' was notified as an exception")
}
end

stacktrace = exception["stacktrace"][0]
expect(stacktrace["lineNumber"]).to eq(1047)
expect(stacktrace["file"]).to end_with("spec/report_spec.rb")
expect(stacktrace["code"]["1046"]).to eq(" it 'uses an appropriate message if nil is notified' do")
expect(stacktrace["code"]["1047"]).to eq(" Bugsnag.notify(nil)")
it "includes bugsnag lines marked out of project" do
notify_test_exception
expect(Bugsnag).to have_sent_notification{ |payload, headers|
exception = get_exception_from_payload(payload)
bugsnag_count = 0
exception["stacktrace"].each do |frame|
if /.*lib\/bugsnag.*\.rb/.match(frame["file"])
bugsnag_count += 1
expect(frame["inProject"]).to be_nil
end
end
expect(bugsnag_count).to be > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a specific number rather than > 0

}
end

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ def have_sent_notification(&matcher)
raise "no matcher provided to have_sent_notification (did you use { })"
end
end
end
end
36 changes: 20 additions & 16 deletions spec/stacktrace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@

describe Bugsnag::Stacktrace do
it "includes code in the stack trace" do
_a = 1
_b = 2
_c = 3
notify_test_exception
_d = 4
_e = 5
_f = 6
begin
_a = 1
_b = 2
_c = 3
"Test".prepnd "T"
_d = 4
_e = 5
_f = 6
rescue Exception => e
Bugsnag.notify(e)
end

expect(Bugsnag).to have_sent_notification{ |payload, headers|
exception = get_exception_from_payload(payload)
starting_line = __LINE__ - 10
expect(exception["stacktrace"][1]["code"]).to eq({
(starting_line + 0).to_s => " _a = 1",
(starting_line + 1).to_s => " _b = 2",
(starting_line + 2).to_s => " _c = 3",
(starting_line + 3).to_s => " notify_test_exception",
(starting_line + 4).to_s => " _d = 4",
(starting_line + 5).to_s => " _e = 5",
(starting_line + 6).to_s => " _f = 6"
starting_line = __LINE__ - 13
expect(exception["stacktrace"][0]["code"]).to eq({
(starting_line + 0).to_s => " _a = 1",
(starting_line + 1).to_s => " _b = 2",
(starting_line + 2).to_s => " _c = 3",
(starting_line + 3).to_s => " \"Test\".prepnd \"T\"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be easier to read if you used single quotes on the outside so you don't have to escape the double quotes inside.

(starting_line + 4).to_s => " _d = 4",
(starting_line + 5).to_s => " _e = 5",
(starting_line + 6).to_s => " _f = 6"
})
}
end
Expand Down