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 5 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
2 changes: 1 addition & 1 deletion lib/bugsnag/stacktrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(backtrace, configuration)
# Parse the stacktrace line

# Skip stacktrace lines inside lib/bugsnag
Cawllec marked this conversation as resolved.
Show resolved Hide resolved
next(nil) if file.nil? || file =~ %r{lib/bugsnag(/|\.rb)}
next(nil) if file.nil?

# Expand relative paths
p = Pathname.new(file)
Expand Down
15 changes: 8 additions & 7 deletions spec/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def gloops
expect(WebMock).to have_requested(:post, "https://notify.bugsnag.com")
end

it "does not mark the top-most stacktrace line as inProject if out of project" do
it "does not mark the top-most non-bugsnag stacktrace line as inProject if out of project" do
Cawllec marked this conversation as resolved.
Show resolved Hide resolved
Bugsnag.configuration.project_root = "/Random/location/here"
Bugsnag.notify(BugsnagTestException.new("It crashed"))

Expand All @@ -512,14 +512,15 @@ def gloops
}
end

it "marks the top-most stacktrace line as inProject if necessary" do
it "marks the top-most non-bugsnag stacktrace line as inProject if necessary" do
Cawllec marked this conversation as resolved.
Show resolved Hide resolved
Bugsnag.configuration.project_root = File.expand_path File.dirname(__FILE__)
Bugsnag.notify(BugsnagTestException.new("It crashed"))
Cawllec marked this conversation as resolved.
Show resolved Hide resolved

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)
top_frame = get_project_frame(exception["stacktrace"])
Cawllec marked this conversation as resolved.
Show resolved Hide resolved
expect(top_frame["inProject"]).to eq(true)
}
end

Expand Down Expand Up @@ -1051,11 +1052,11 @@ def gloops
expect(exception["errorClass"]).to eq("RuntimeError")
expect(exception["message"]).to eq("'nil' was notified as an exception")

stacktrace = exception["stacktrace"][0]
expect(stacktrace["lineNumber"]).to eq(1047)
stacktrace = get_project_frame(exception["stacktrace"])
Cawllec marked this conversation as resolved.
Show resolved Hide resolved
expect(stacktrace["lineNumber"]).to eq(1048)
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)")
expect(stacktrace["code"]["1047"]).to eq(" it 'uses an appropriate message if nil is notified' do")
expect(stacktrace["code"]["1048"]).to eq(" Bugsnag.notify(nil)")
}
end

Expand Down
15 changes: 15 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,18 @@ def have_sent_notification(&matcher)
end
end
end

def get_project_frame(stacktrace, count=0)
Cawllec marked this conversation as resolved.
Show resolved Hide resolved
index = 0
stacktrace.find do |frame|
found = false
if /.*lib\/bugsnag.*\.rb/.match(frame["file"]).nil?
if index == count
found = true
else
index += 1
found = false
end
end
end
end
20 changes: 18 additions & 2 deletions spec/stacktrace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

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_frame = get_project_frame(exception["stacktrace"], 1)
Cawllec marked this conversation as resolved.
Show resolved Hide resolved
starting_line = __LINE__ - 11
expect(starting_frame["code"]).to eq({
(starting_line + 0).to_s => " _a = 1",
(starting_line + 1).to_s => " _b = 2",
(starting_line + 2).to_s => " _c = 3",
Expand All @@ -25,6 +26,21 @@
}
end

it "includes bugsnag lines marked out of project" do
Cawllec marked this conversation as resolved.
Show resolved Hide resolved
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
}
end

it "allows you to disable sending code" do
Bugsnag.configuration.send_code = false

Expand Down