bugsnag 6.12.1 → 6.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.buildkite/pipeline.yml +470 -0
- data/.rubocop.yml +55 -0
- data/.rubocop_todo.yml +530 -160
- data/CHANGELOG.md +73 -0
- data/CONTRIBUTING.md +1 -9
- data/Gemfile +14 -7
- data/TESTING.md +81 -0
- data/VERSION +1 -1
- data/docker-compose.yml +46 -0
- data/dockerfiles/Dockerfile.jruby-unit-tests +13 -0
- data/dockerfiles/Dockerfile.ruby-maze-runner +26 -0
- data/dockerfiles/Dockerfile.ruby-unit-tests +12 -0
- data/features/delayed_job.feature +6 -22
- data/features/fixtures/delayed_job/Dockerfile +2 -4
- data/features/fixtures/delayed_job/app/Gemfile +1 -1
- data/features/fixtures/delayed_job/app/Rakefile +18 -0
- data/features/fixtures/docker-compose.yml +32 -40
- data/features/fixtures/expected_breadcrumbs/active_job.json +9 -0
- data/features/fixtures/expected_breadcrumbs/mongo_failed.json +15 -0
- data/features/fixtures/expected_breadcrumbs/mongo_filtered_request.json +15 -0
- data/features/fixtures/expected_breadcrumbs/mongo_filtered_result.json +15 -0
- data/features/fixtures/expected_breadcrumbs/mongo_success.json +14 -0
- data/features/fixtures/expected_breadcrumbs/request.json +13 -0
- data/features/fixtures/expected_breadcrumbs/sql_with_bindings.json +12 -0
- data/features/fixtures/expected_breadcrumbs/sql_without_bindings.json +11 -0
- data/features/fixtures/plain/Dockerfile +2 -2
- data/features/fixtures/plain/app/app.rb +1 -3
- data/features/fixtures/plain/app/delivery/fork_threadpool.rb +3 -1
- data/features/fixtures/plain/app/report_modification/initiators/handled_on_error.rb +10 -0
- data/features/fixtures/plain/app/report_modification/initiators/unhandled_on_error.rb +11 -0
- data/features/fixtures/plain/app/stack_frame_modification/initiators/handled_on_error.rb +29 -0
- data/features/fixtures/plain/app/stack_frame_modification/initiators/unhandled_on_error.rb +26 -0
- data/features/fixtures/plain/app/unhandled/{Interrupt.rb → interrupt.rb} +0 -0
- data/features/fixtures/rack1/Dockerfile +2 -2
- data/features/fixtures/rack2/Dockerfile +2 -2
- data/features/fixtures/rails3/Dockerfile +2 -2
- data/features/fixtures/rails3/app/Gemfile +4 -0
- data/features/fixtures/rails3/app/config/initializers/bugsnag.rb +11 -2
- data/features/fixtures/rails4/Dockerfile +2 -5
- data/features/fixtures/rails4/app/config/initializers/bugsnag.rb +10 -1
- data/features/fixtures/rails5/Dockerfile +2 -2
- data/features/fixtures/rails5/app/Gemfile +3 -2
- data/features/fixtures/rails5/app/config/initializers/bugsnag.rb +10 -1
- data/features/fixtures/rails6/Dockerfile +2 -2
- data/features/fixtures/rails6/app/Gemfile +3 -2
- data/features/fixtures/rails6/app/app/controllers/mongo_controller.rb +22 -0
- data/features/fixtures/rails6/app/app/models/mongo_model.rb +6 -0
- data/features/fixtures/rails6/app/config/environments/development.rb +2 -0
- data/features/fixtures/rails6/app/config/environments/production.rb +1 -0
- data/features/fixtures/rails6/app/config/environments/rails_env.rb +1 -0
- data/features/fixtures/rails6/app/config/environments/test.rb +1 -0
- data/features/fixtures/rails6/app/config/initializers/bugsnag.rb +10 -1
- data/features/fixtures/rails6/app/config/mongoid.yml +23 -0
- data/features/fixtures/rails6/app/config/routes.rb +4 -0
- data/features/fixtures/resque/Dockerfile +2 -2
- data/features/fixtures/sidekiq/Dockerfile +5 -7
- data/features/fixtures/sidekiq/app/Gemfile +2 -1
- data/features/fixtures/sidekiq/app/Rakefile.rb +14 -0
- data/features/fixtures/sinatra1/Dockerfile +2 -2
- data/features/fixtures/sinatra2/Dockerfile +2 -2
- data/features/plain_features/add_tab.feature +30 -97
- data/features/plain_features/app_type.feature +6 -25
- data/features/plain_features/app_version.feature +6 -25
- data/features/plain_features/auto_notify.feature +4 -20
- data/features/plain_features/delivery.feature +12 -60
- data/features/plain_features/exception_data.feature +24 -94
- data/features/plain_features/filters.feature +9 -43
- data/features/plain_features/handled_errors.feature +16 -78
- data/features/plain_features/ignore_classes.feature +5 -23
- data/features/plain_features/ignore_report.feature +8 -24
- data/features/plain_features/proxies.feature +13 -56
- data/features/plain_features/release_stages.feature +9 -40
- data/features/plain_features/report_api_key.feature +11 -35
- data/features/plain_features/report_severity.feature +10 -35
- data/features/plain_features/report_stack_frames.feature +29 -93
- data/features/plain_features/report_user.feature +29 -96
- data/features/plain_features/unhandled_errors.feature +17 -88
- data/features/rails_features/api_key.feature +12 -58
- data/features/rails_features/app_type.feature +13 -58
- data/features/rails_features/app_version.feature +19 -80
- data/features/rails_features/auto_capture_sessions.feature +31 -112
- data/features/rails_features/auto_notify.feature +28 -105
- data/features/rails_features/before_notify.feature +18 -83
- data/features/rails_features/breadcrumbs.feature +40 -137
- data/features/rails_features/handled.feature +18 -82
- data/features/rails_features/ignore_classes.feature +12 -51
- data/features/rails_features/meta_data_filters.feature +9 -33
- data/features/rails_features/mongo_breadcrumbs.feature +22 -96
- data/features/rails_features/on_error.feature +29 -0
- data/features/rails_features/project_root.feature +19 -84
- data/features/rails_features/release_stage.feature +20 -82
- data/features/rails_features/send_code.feature +13 -55
- data/features/rails_features/send_environment.feature +7 -33
- data/features/rails_features/unhandled.feature +6 -31
- data/features/rails_features/user_info.feature +27 -65
- data/features/sidekiq.feature +12 -79
- data/features/steps/ruby_notifier_steps.rb +59 -15
- data/features/support/env.rb +12 -45
- data/lib/bugsnag.rb +109 -21
- data/lib/bugsnag/breadcrumbs/breadcrumbs.rb +0 -2
- data/lib/bugsnag/breadcrumbs/validator.rb +0 -6
- data/lib/bugsnag/cleaner.rb +129 -60
- data/lib/bugsnag/code_extractor.rb +137 -0
- data/lib/bugsnag/configuration.rb +58 -1
- data/lib/bugsnag/helpers.rb +2 -4
- data/lib/bugsnag/integrations/que.rb +7 -4
- data/lib/bugsnag/middleware/discard_error_class.rb +30 -0
- data/lib/bugsnag/middleware/exception_meta_data.rb +15 -9
- data/lib/bugsnag/middleware/ignore_error_class.rb +2 -0
- data/lib/bugsnag/middleware/rack_request.rb +2 -4
- data/lib/bugsnag/middleware_stack.rb +38 -3
- data/lib/bugsnag/on_error_callbacks.rb +33 -0
- data/lib/bugsnag/report.rb +4 -14
- data/lib/bugsnag/session_tracker.rb +3 -3
- data/lib/bugsnag/stacktrace.rb +28 -75
- data/spec/breadcrumbs/breadcrumb_spec.rb +1 -1
- data/spec/breadcrumbs/validator_spec.rb +1 -26
- data/spec/bugsnag_spec.rb +2 -2
- data/spec/cleaner_spec.rb +202 -10
- data/spec/code_extractor_spec.rb +129 -0
- data/spec/configuration_spec.rb +16 -1
- data/spec/fixtures/apps/rails-initializer-config/Gemfile +5 -1
- data/spec/fixtures/apps/rails-invalid-initializer-config/Gemfile +5 -1
- data/spec/fixtures/apps/rails-no-config/Gemfile +5 -1
- data/spec/fixtures/crashes/file1.rb +29 -0
- data/spec/fixtures/crashes/file2.rb +25 -0
- data/spec/fixtures/crashes/file_with_long_lines.rb +7 -0
- data/spec/fixtures/crashes/functions.rb +29 -0
- data/spec/fixtures/crashes/short_file.rb +2 -0
- data/spec/helper_spec.rb +0 -31
- data/spec/integrations/logger_spec.rb +1 -1
- data/spec/integrations/rack_spec.rb +8 -6
- data/spec/integrations/rake_spec.rb +1 -1
- data/spec/on_error_spec.rb +332 -0
- data/spec/report_spec.rb +331 -30
- data/spec/spec_helper.rb +14 -1
- data/spec/stacktrace_spec.rb +427 -74
- metadata +36 -7
- data/.travis.yml +0 -117
- data/features/plain_features/api_key.feature +0 -25
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bugsnag::CodeExtractor do
|
4
|
+
it "extracts code from a file and adds it to the given hash" do
|
5
|
+
file1_hash = { lineNumber: 5 }
|
6
|
+
file2_hash = { lineNumber: 7 }
|
7
|
+
|
8
|
+
code_extractor = Bugsnag::CodeExtractor.new(Bugsnag::Configuration.new)
|
9
|
+
code_extractor.add_file("spec/fixtures/crashes/file1.rb", file1_hash)
|
10
|
+
code_extractor.add_file("spec/fixtures/crashes/file2.rb", file2_hash)
|
11
|
+
|
12
|
+
code_extractor.extract!
|
13
|
+
|
14
|
+
expect(file1_hash).to eq({
|
15
|
+
lineNumber: 5,
|
16
|
+
code: {
|
17
|
+
2 => "",
|
18
|
+
3 => "module File1",
|
19
|
+
4 => " def self.foo1",
|
20
|
+
5 => " File2.foo2",
|
21
|
+
6 => " end",
|
22
|
+
7 => "",
|
23
|
+
8 => " def self.bar1"
|
24
|
+
}
|
25
|
+
})
|
26
|
+
|
27
|
+
expect(file2_hash).to eq({
|
28
|
+
lineNumber: 7,
|
29
|
+
code: {
|
30
|
+
4 => " end",
|
31
|
+
5 => "",
|
32
|
+
6 => " def self.bar2",
|
33
|
+
7 => " File1.baz1",
|
34
|
+
8 => " end",
|
35
|
+
9 => "",
|
36
|
+
10 => " def self.baz2"
|
37
|
+
}
|
38
|
+
})
|
39
|
+
end
|
40
|
+
|
41
|
+
it "handles extracting code from the first & last line in a file" do
|
42
|
+
file1_hash = { lineNumber: 1 }
|
43
|
+
file2_hash = { lineNumber: 25 }
|
44
|
+
|
45
|
+
code_extractor = Bugsnag::CodeExtractor.new(Bugsnag::Configuration.new)
|
46
|
+
code_extractor.add_file("spec/fixtures/crashes/file1.rb", file1_hash)
|
47
|
+
code_extractor.add_file("spec/fixtures/crashes/file2.rb", file2_hash)
|
48
|
+
|
49
|
+
code_extractor.extract!
|
50
|
+
|
51
|
+
expect(file1_hash).to eq({
|
52
|
+
lineNumber: 1,
|
53
|
+
code: {
|
54
|
+
1 => "require_relative 'file2'",
|
55
|
+
2 => "",
|
56
|
+
3 => "module File1",
|
57
|
+
4 => " def self.foo1",
|
58
|
+
5 => " File2.foo2",
|
59
|
+
6 => " end",
|
60
|
+
7 => ""
|
61
|
+
}
|
62
|
+
})
|
63
|
+
|
64
|
+
expect(file2_hash).to eq({
|
65
|
+
lineNumber: 25,
|
66
|
+
code: {
|
67
|
+
19 => " puts 'abcdef2'",
|
68
|
+
20 => " end",
|
69
|
+
21 => "",
|
70
|
+
22 => " def self.abcdefghi2",
|
71
|
+
23 => " puts 'abcdefghi2'",
|
72
|
+
24 => " end",
|
73
|
+
25 => "end"
|
74
|
+
}
|
75
|
+
})
|
76
|
+
end
|
77
|
+
|
78
|
+
it "truncates lines to a maximum of 200 characters" do
|
79
|
+
hash = { lineNumber: 4 }
|
80
|
+
|
81
|
+
code_extractor = Bugsnag::CodeExtractor.new(Bugsnag::Configuration.new)
|
82
|
+
code_extractor.add_file("spec/fixtures/crashes/file_with_long_lines.rb", hash)
|
83
|
+
|
84
|
+
code_extractor.extract!
|
85
|
+
|
86
|
+
# rubocop:disable Layout/LineLength
|
87
|
+
expect(hash).to eq({
|
88
|
+
lineNumber: 4,
|
89
|
+
code: {
|
90
|
+
1 => "# rubocop:disable Layout/LineLength",
|
91
|
+
2 => "def a_super_long_function_name_that_would_be_really_impractical_to_use_but_luckily_this_is_just_for_a_test_to_prove_we_can_handle_really_long_lines_of_code_that_go_over_200_characters_and_some_more_pa",
|
92
|
+
3 => " puts 'This is a shorter string'",
|
93
|
+
4 => " puts 'A more realistic example of when a line would be really long is long strings such as this one, which extends over the 200 character limit by containing a lot of excess words for padding its le",
|
94
|
+
5 => " puts 'and another shorter string for comparison'",
|
95
|
+
6 => "end",
|
96
|
+
7 => "# rubocop:enable Layout/LineLength",
|
97
|
+
}
|
98
|
+
})
|
99
|
+
# rubocop:enable Layout/LineLength
|
100
|
+
end
|
101
|
+
|
102
|
+
it "rescues exceptions raised in extract!" do
|
103
|
+
file1_hash = { lineNumber: 1 }
|
104
|
+
file2_hash = { lineNumber: 25 }
|
105
|
+
|
106
|
+
code_extractor = Bugsnag::CodeExtractor.new(Bugsnag::Configuration.new)
|
107
|
+
code_extractor.add_file("spec/fixtures/crashes/file1.rb", file1_hash)
|
108
|
+
code_extractor.add_file("spec/fixtures/crashes/file2.rb", file2_hash)
|
109
|
+
|
110
|
+
file1_hash[:first_line_number] = nil
|
111
|
+
|
112
|
+
code_extractor.extract!
|
113
|
+
|
114
|
+
expect(file1_hash).to eq({ lineNumber: 1, code: nil })
|
115
|
+
|
116
|
+
expect(file2_hash).to eq({
|
117
|
+
lineNumber: 25,
|
118
|
+
code: {
|
119
|
+
19 => " puts 'abcdef2'",
|
120
|
+
20 => " end",
|
121
|
+
21 => "",
|
122
|
+
22 => " def self.abcdefghi2",
|
123
|
+
23 => " puts 'abcdefghi2'",
|
124
|
+
24 => " end",
|
125
|
+
25 => "end"
|
126
|
+
}
|
127
|
+
})
|
128
|
+
end
|
129
|
+
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -332,10 +332,14 @@ describe Bugsnag::Configuration do
|
|
332
332
|
end
|
333
333
|
end
|
334
334
|
|
335
|
-
it "should have exit exception classes
|
335
|
+
it "should have exit exception classes in ignore_classes by default" do
|
336
336
|
expect(subject.ignore_classes).to eq(Set.new([SystemExit, SignalException]))
|
337
337
|
end
|
338
338
|
|
339
|
+
it "should have nothing in discard_classes by default" do
|
340
|
+
expect(subject.discard_classes).to eq(Set.new([]))
|
341
|
+
end
|
342
|
+
|
339
343
|
describe "#breadcrumbs" do
|
340
344
|
it "first returns a new circular buffer" do
|
341
345
|
buffer = subject.breadcrumbs
|
@@ -427,4 +431,15 @@ describe Bugsnag::Configuration do
|
|
427
431
|
expect(second_array).to eq([1, 2])
|
428
432
|
end
|
429
433
|
end
|
434
|
+
|
435
|
+
describe "#vendor_path" do
|
436
|
+
it "returns the default vendor path" do
|
437
|
+
expect(subject.vendor_path).to eq(Bugsnag::Configuration::DEFAULT_VENDOR_PATH)
|
438
|
+
end
|
439
|
+
|
440
|
+
it "returns the defined vendor path" do
|
441
|
+
subject.vendor_path = /foo/
|
442
|
+
expect(subject.vendor_path).to eq(/foo/)
|
443
|
+
end
|
444
|
+
end
|
430
445
|
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
3
|
+
ruby_version = Gem::Version.new(RUBY_VERSION.dup)
|
4
|
+
|
5
|
+
gem 'railties', ruby_version <= Gem::Version.new('2.6') ? '4.2.10' : '~> 6.0.2', require: %w(action_controller rails)
|
6
|
+
gem 'rake', ruby_version <= Gem::Version.new('1.9.3') ? '~> 11.3.0' : '~> 12.3.0'
|
7
|
+
gem 'minitest', ruby_version <= Gem::Version.new('2.2') ? '5.11.3' : '~> 5.13.0'
|
4
8
|
gem 'nokogiri', '1.6.8'
|
5
9
|
gem 'bugsnag', path: '../../../..'
|
@@ -1,5 +1,9 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
3
|
+
ruby_version = Gem::Version.new(RUBY_VERSION.dup)
|
4
|
+
|
5
|
+
gem 'railties', ruby_version <= Gem::Version.new('2.6') ? '4.2.10' : '~> 6.0.2', require: %w(action_controller rails)
|
6
|
+
gem 'rake', ruby_version <= Gem::Version.new('1.9.3') ? '~> 11.3.0' : '~> 12.3.0'
|
7
|
+
gem 'minitest', ruby_version <= Gem::Version.new('2.2') ? '5.11.3' : '~> 5.13.0'
|
4
8
|
gem 'nokogiri', '1.6.8'
|
5
9
|
gem 'bugsnag', path: '../../../..'
|
@@ -1,5 +1,9 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
3
|
+
ruby_version = Gem::Version.new(RUBY_VERSION.dup)
|
4
|
+
|
5
|
+
gem 'railties', ruby_version <= Gem::Version.new('2.6') ? '4.2.10' : '~> 6.0.2', require: %w(action_controller rails)
|
6
|
+
gem 'rake', ruby_version <= Gem::Version.new('1.9.3') ? '~> 11.3.0' : '~> 12.3.0'
|
7
|
+
gem 'minitest', ruby_version <= Gem::Version.new('2.2') ? '5.11.3' : '~> 5.13.0'
|
4
8
|
gem 'nokogiri', '1.6.8'
|
5
9
|
gem 'bugsnag', path: '../../../..'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'file2'
|
2
|
+
|
3
|
+
module File1
|
4
|
+
def self.foo1
|
5
|
+
File2.foo2
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.bar1
|
9
|
+
File2.bar2
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.baz1
|
13
|
+
File2.baz2
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.abc1
|
17
|
+
puts 'abc'
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.abcdef1
|
21
|
+
puts 'abcdef1'
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.abcdefghi1
|
25
|
+
puts 'abcdefghi1'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
File1.foo1
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module File2
|
2
|
+
def self.foo2
|
3
|
+
File1.bar1
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.bar2
|
7
|
+
File1.baz1
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.baz2
|
11
|
+
raise 'uh oh'
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.abc2
|
15
|
+
puts 'abc'
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.abcdef2
|
19
|
+
puts 'abcdef2'
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.abcdefghi2
|
23
|
+
puts 'abcdefghi2'
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# rubocop:disable Layout/LineLength
|
2
|
+
def a_super_long_function_name_that_would_be_really_impractical_to_use_but_luckily_this_is_just_for_a_test_to_prove_we_can_handle_really_long_lines_of_code_that_go_over_200_characters_and_some_more_padding
|
3
|
+
puts 'This is a shorter string'
|
4
|
+
puts 'A more realistic example of when a line would be really long is long strings such as this one, which extends over the 200 character limit by containing a lot of excess words for padding its length so that it is super long'
|
5
|
+
puts 'and another shorter string for comparison'
|
6
|
+
end
|
7
|
+
# rubocop:enable Layout/LineLength
|
@@ -0,0 +1,29 @@
|
|
1
|
+
def foo
|
2
|
+
bar
|
3
|
+
end
|
4
|
+
|
5
|
+
def bar
|
6
|
+
baz
|
7
|
+
end
|
8
|
+
|
9
|
+
def baz
|
10
|
+
xyz
|
11
|
+
end
|
12
|
+
|
13
|
+
def xyz
|
14
|
+
raise 'uh oh'
|
15
|
+
end
|
16
|
+
|
17
|
+
def abc
|
18
|
+
puts 'abc'
|
19
|
+
end
|
20
|
+
|
21
|
+
def abcdef
|
22
|
+
puts 'abcdef'
|
23
|
+
end
|
24
|
+
|
25
|
+
def abcdefghi
|
26
|
+
puts 'abcdefghi'
|
27
|
+
end
|
28
|
+
|
29
|
+
foo
|
data/spec/helper_spec.rb
CHANGED
@@ -4,23 +4,7 @@ require 'spec_helper'
|
|
4
4
|
require 'set'
|
5
5
|
|
6
6
|
describe Bugsnag::Helpers do
|
7
|
-
|
8
7
|
describe "trim_if_needed" do
|
9
|
-
|
10
|
-
it "breaks recursion" do
|
11
|
-
a = [1, 2, 3]
|
12
|
-
b = [2, a]
|
13
|
-
a << b
|
14
|
-
value = Bugsnag::Helpers.trim_if_needed(a)
|
15
|
-
expect(value).to eq([1, 2, 3, [2, "[RECURSION]"]])
|
16
|
-
end
|
17
|
-
|
18
|
-
it "does not break equal objects without recursion" do
|
19
|
-
data = [1, [1, 2], [1, 2], "a"]
|
20
|
-
value = Bugsnag::Helpers.trim_if_needed(data)
|
21
|
-
expect(value).to eq data
|
22
|
-
end
|
23
|
-
|
24
8
|
it "preserves bool types" do
|
25
9
|
value = Bugsnag::Helpers.trim_if_needed([1, 3, true, "NO", "2", false])
|
26
10
|
expect(value[2]).to be_a(TrueClass)
|
@@ -39,21 +23,7 @@ describe Bugsnag::Helpers do
|
|
39
23
|
expect(value[4]).to be_a(String)
|
40
24
|
end
|
41
25
|
|
42
|
-
context "an object will throw if `to_s` is called" do
|
43
|
-
class StringRaiser
|
44
|
-
def to_s
|
45
|
-
raise 'Oh no you do not!'
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it "uses the string '[RAISED]' instead" do
|
50
|
-
value = Bugsnag::Helpers.trim_if_needed([1, 3, StringRaiser.new])
|
51
|
-
expect(value[2]).to eq "[RAISED]"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
26
|
context "payload length is less than allowed" do
|
56
|
-
|
57
27
|
it "does not change strings" do
|
58
28
|
value = SecureRandom.hex(4096)
|
59
29
|
expect(Bugsnag::Helpers.trim_if_needed(value)).to eq value
|
@@ -71,7 +41,6 @@ describe Bugsnag::Helpers do
|
|
71
41
|
end
|
72
42
|
|
73
43
|
context "payload length is greater than allowed" do
|
74
|
-
|
75
44
|
it "trims metadata strings" do
|
76
45
|
payload = {
|
77
46
|
:events => [{
|
@@ -61,7 +61,7 @@ describe 'Configuration.logger' do
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
context '
|
64
|
+
context 'when the API key is invalid in the bugsnag initializer' do
|
65
65
|
it 'logs a warning' do
|
66
66
|
skip "Incompatible with Ruby <2.0 and JRuby" if incompatible
|
67
67
|
output = run_app('rails-invalid-initializer-config')
|
@@ -127,9 +127,10 @@ describe Bugsnag::Rack do
|
|
127
127
|
expect(report).to receive(:context=).with("TEST /TEST_PATH")
|
128
128
|
expect(report).to receive(:user).and_return({})
|
129
129
|
|
130
|
-
config =
|
131
|
-
|
132
|
-
|
130
|
+
config = Bugsnag.configuration
|
131
|
+
config.send_environment = true
|
132
|
+
config.meta_data_filters = ['email']
|
133
|
+
|
133
134
|
allow(report).to receive(:configuration).and_return(config)
|
134
135
|
expect(report).to receive(:add_tab).once.with(:request, {
|
135
136
|
:url => "http://test_host/TEST_PATH?email=[FILTERED]&another_param=thing",
|
@@ -187,9 +188,10 @@ describe Bugsnag::Rack do
|
|
187
188
|
expect(report).to receive(:context=).with("TEST /TEST_PATH")
|
188
189
|
expect(report).to receive(:user).and_return({})
|
189
190
|
|
190
|
-
config =
|
191
|
-
|
192
|
-
|
191
|
+
config = Bugsnag.configuration
|
192
|
+
config.send_environment = true
|
193
|
+
config.meta_data_filters = []
|
194
|
+
|
193
195
|
allow(report).to receive(:configuration).and_return(config)
|
194
196
|
expect(report).to receive(:add_tab).once.with(:environment, rack_env)
|
195
197
|
expect(report).to receive(:add_tab).once.with(:request, {
|
@@ -58,7 +58,7 @@ describe "Bugsnag Rake integration" do
|
|
58
58
|
ENV['BUGSNAG_TEST_SERVER_PORT'] = server.config[:Port].to_s
|
59
59
|
task_fixtures_path = File.join(File.dirname(__FILE__), '../fixtures', 'tasks')
|
60
60
|
Dir.chdir(task_fixtures_path) do
|
61
|
-
system("
|
61
|
+
system("../../../bin/rake test:crash")
|
62
62
|
end
|
63
63
|
|
64
64
|
result = request()
|
@@ -0,0 +1,332 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "on_error callbacks" do
|
4
|
+
it "runs callbacks on notify" do
|
5
|
+
callback1 = proc {|report| report.add_tab(:important, { hello: "world" }) }
|
6
|
+
callback2 = proc {|report| report.add_tab(:significant, { hey: "earth" }) }
|
7
|
+
|
8
|
+
Bugsnag.add_on_error(callback1)
|
9
|
+
Bugsnag.add_on_error(callback2)
|
10
|
+
|
11
|
+
Bugsnag.notify(RuntimeError.new("Oh no!"))
|
12
|
+
|
13
|
+
expect(Bugsnag).to(have_sent_notification do |payload, _headers|
|
14
|
+
event = get_event_from_payload(payload)
|
15
|
+
|
16
|
+
expect(event["metaData"]["important"]).to eq({ "hello" => "world" })
|
17
|
+
expect(event["metaData"]["significant"]).to eq({ "hey" => "earth" })
|
18
|
+
end)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can add callbacks in a configure block" do
|
22
|
+
callback1 = proc {|report| report.add_tab(:important, { hello: "world" }) }
|
23
|
+
callback2 = proc {|report| report.add_tab(:significant, { hey: "earth" }) }
|
24
|
+
|
25
|
+
Bugsnag.configure do |config|
|
26
|
+
config.add_on_error(callback1)
|
27
|
+
config.add_on_error(callback2)
|
28
|
+
end
|
29
|
+
|
30
|
+
Bugsnag.notify(RuntimeError.new("Oh no!"))
|
31
|
+
|
32
|
+
expect(Bugsnag).to(have_sent_notification do |payload, _headers|
|
33
|
+
event = get_event_from_payload(payload)
|
34
|
+
|
35
|
+
expect(event["metaData"]["important"]).to eq({ "hello" => "world" })
|
36
|
+
expect(event["metaData"]["significant"]).to eq({ "hey" => "earth" })
|
37
|
+
end)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "can remove an already registered callback" do
|
41
|
+
callback1 = proc {|report| report.add_tab(:important, { hello: "world" }) }
|
42
|
+
callback2 = proc {|report| report.add_tab(:significant, { hey: "earth" }) }
|
43
|
+
|
44
|
+
Bugsnag.add_on_error(callback1)
|
45
|
+
Bugsnag.add_on_error(callback2)
|
46
|
+
|
47
|
+
Bugsnag.remove_on_error(callback1)
|
48
|
+
|
49
|
+
Bugsnag.notify(RuntimeError.new("Oh no!"))
|
50
|
+
|
51
|
+
expect(Bugsnag).to(have_sent_notification do |payload, _headers|
|
52
|
+
event = get_event_from_payload(payload)
|
53
|
+
|
54
|
+
expect(event["metaData"]["important"]).to be_nil
|
55
|
+
expect(event["metaData"]["significant"]).to eq({ "hey" => "earth" })
|
56
|
+
end)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can remove all registered callbacks" do
|
60
|
+
callback1 = proc {|report| report.add_tab(:important, { hello: "world" }) }
|
61
|
+
callback2 = proc {|report| report.add_tab(:significant, { hey: "earth" }) }
|
62
|
+
|
63
|
+
Bugsnag.add_on_error(callback1)
|
64
|
+
Bugsnag.add_on_error(callback2)
|
65
|
+
|
66
|
+
Bugsnag.remove_on_error(callback2)
|
67
|
+
Bugsnag.remove_on_error(callback1)
|
68
|
+
|
69
|
+
Bugsnag.notify(RuntimeError.new("Oh no!"))
|
70
|
+
|
71
|
+
expect(Bugsnag).to(have_sent_notification do |payload, _headers|
|
72
|
+
event = get_event_from_payload(payload)
|
73
|
+
|
74
|
+
expect(event["metaData"]["important"]).to be_nil
|
75
|
+
expect(event["metaData"]["significant"]).to be_nil
|
76
|
+
end)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "does not remove an identical callback if it is not the same Proc" do
|
80
|
+
callback1 = proc {|report| report.add_tab(:important, { hello: "world" }) }
|
81
|
+
callback1_duplicate = proc {|report| report.add_tab(:important, { hello: "world" }) }
|
82
|
+
|
83
|
+
Bugsnag.add_on_error(callback1)
|
84
|
+
Bugsnag.remove_on_error(callback1_duplicate)
|
85
|
+
|
86
|
+
Bugsnag.notify(RuntimeError.new("Oh no!"))
|
87
|
+
|
88
|
+
expect(Bugsnag).to(have_sent_notification do |payload, _headers|
|
89
|
+
event = get_event_from_payload(payload)
|
90
|
+
|
91
|
+
expect(event["metaData"]["important"]).to eq({ "hello" => "world" })
|
92
|
+
end)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "can re-add callbacks that have previously been removed" do
|
96
|
+
callback1 = proc {|report| report.add_tab(:important, { hello: "world" }) }
|
97
|
+
callback2 = proc {|report| report.add_tab(:significant, { hey: "earth" }) }
|
98
|
+
|
99
|
+
Bugsnag.add_on_error(callback1)
|
100
|
+
Bugsnag.add_on_error(callback2)
|
101
|
+
|
102
|
+
Bugsnag.remove_on_error(callback1)
|
103
|
+
|
104
|
+
Bugsnag.add_on_error(callback1)
|
105
|
+
|
106
|
+
Bugsnag.notify(RuntimeError.new("Oh no!"))
|
107
|
+
|
108
|
+
expect(Bugsnag).to(have_sent_notification do |payload, _headers|
|
109
|
+
event = get_event_from_payload(payload)
|
110
|
+
|
111
|
+
expect(event["metaData"]["important"]).to eq({ "hello" => "world" })
|
112
|
+
expect(event["metaData"]["significant"]).to eq({ "hey" => "earth" })
|
113
|
+
end)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "will only add a callback once" do
|
117
|
+
called_count = 0
|
118
|
+
|
119
|
+
callback = proc do |report|
|
120
|
+
called_count += 1
|
121
|
+
|
122
|
+
report.add_tab(:important, { called: called_count })
|
123
|
+
end
|
124
|
+
|
125
|
+
1.upto(10) do |i|
|
126
|
+
Bugsnag.add_on_error(callback)
|
127
|
+
end
|
128
|
+
|
129
|
+
Bugsnag.notify(RuntimeError.new("Oh no!"))
|
130
|
+
|
131
|
+
expect(Bugsnag).to(have_sent_notification do |payload, _headers|
|
132
|
+
event = get_event_from_payload(payload)
|
133
|
+
|
134
|
+
expect(called_count).to be(1)
|
135
|
+
expect(event["metaData"]["important"]).to eq({ "called" => 1 })
|
136
|
+
end)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "will ignore the report and stop calling callbacks if one returns false" do
|
140
|
+
logger = spy('logger')
|
141
|
+
Bugsnag.configuration.logger = logger
|
142
|
+
|
143
|
+
called_count = 0
|
144
|
+
|
145
|
+
callback1 = proc { called_count += 1 }
|
146
|
+
callback2 = proc { called_count += 1 }
|
147
|
+
callback3 = proc { false }
|
148
|
+
callback4 = proc { called_count += 1 }
|
149
|
+
callback5 = proc { called_count += 1 }
|
150
|
+
|
151
|
+
Bugsnag.add_on_error(callback1)
|
152
|
+
Bugsnag.add_on_error(callback2)
|
153
|
+
Bugsnag.add_on_error(callback3)
|
154
|
+
Bugsnag.add_on_error(callback4)
|
155
|
+
Bugsnag.add_on_error(callback5)
|
156
|
+
|
157
|
+
Bugsnag.notify(RuntimeError.new("Oh no!"))
|
158
|
+
|
159
|
+
expect(Bugsnag).not_to have_sent_notification
|
160
|
+
expect(called_count).to be(2)
|
161
|
+
|
162
|
+
expect(logger).to have_received(:debug).with("[Bugsnag]") do |&block|
|
163
|
+
expect(block.call).to eq("Not notifying RuntimeError due to ignore being signified in user provided middleware")
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
it "callbacks are called in the same order they are added (FIFO)" do
|
168
|
+
callback1 = proc do |report|
|
169
|
+
expect(report.meta_data[:important]).to be_nil
|
170
|
+
|
171
|
+
report.add_tab(:important, { magic_number: 9 })
|
172
|
+
end
|
173
|
+
|
174
|
+
callback2 = proc do |report|
|
175
|
+
expect(report.meta_data[:important]).to eq({ magic_number: 9 })
|
176
|
+
|
177
|
+
report.add_tab(:important, { magic_number: 99 })
|
178
|
+
end
|
179
|
+
|
180
|
+
callback3 = proc do |report|
|
181
|
+
expect(report.meta_data[:important]).to eq({ magic_number: 99 })
|
182
|
+
|
183
|
+
report.add_tab(:important, { magic_number: 999 })
|
184
|
+
end
|
185
|
+
|
186
|
+
Bugsnag.add_on_error(callback1)
|
187
|
+
Bugsnag.add_on_error(callback2)
|
188
|
+
Bugsnag.add_on_error(callback3)
|
189
|
+
|
190
|
+
Bugsnag.notify(RuntimeError.new("Oh no!"))
|
191
|
+
|
192
|
+
expect(Bugsnag).to(have_sent_notification do |payload, _headers|
|
193
|
+
event = get_event_from_payload(payload)
|
194
|
+
|
195
|
+
expect(event["metaData"]["important"]).to eq({ "magic_number" => 999 })
|
196
|
+
end)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "callbacks continue being called after a callback raises" do
|
200
|
+
logger = spy('logger')
|
201
|
+
Bugsnag.configuration.logger = logger
|
202
|
+
|
203
|
+
callback1 = proc {|report| report.add_tab(:important, { a: "b" }) }
|
204
|
+
callback2 = proc {|_report| raise "bad things" }
|
205
|
+
callback3 = proc {|report| report.add_tab(:important, { c: "d" }) }
|
206
|
+
|
207
|
+
Bugsnag.add_on_error(callback1)
|
208
|
+
Bugsnag.add_on_error(callback2)
|
209
|
+
Bugsnag.add_on_error(callback3)
|
210
|
+
|
211
|
+
Bugsnag.notify(RuntimeError.new("Oh no!"))
|
212
|
+
|
213
|
+
expect(Bugsnag).to(have_sent_notification do |payload, _headers|
|
214
|
+
event = get_event_from_payload(payload)
|
215
|
+
|
216
|
+
expect(event["metaData"]["important"]).to eq({ "a" => "b", "c" => "d" })
|
217
|
+
end)
|
218
|
+
|
219
|
+
message_index = 0
|
220
|
+
expected_messages = [
|
221
|
+
/^Error occurred in on_error callback: 'bad things'$/,
|
222
|
+
/^on_error callback stacktrace:/
|
223
|
+
]
|
224
|
+
|
225
|
+
expect(logger).to have_received(:warn).with("[Bugsnag]").twice do |&block|
|
226
|
+
expect(block.call).to match(expected_messages[message_index])
|
227
|
+
message_index += 1
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
it "runs callbacks even if no other middleware is registered" do
|
232
|
+
# Reset the middleware stack so any default middleware are removed
|
233
|
+
Bugsnag.configuration.middleware = Bugsnag::MiddlewareStack.new
|
234
|
+
|
235
|
+
callback1 = proc {|report| report.add_tab(:important, { hello: "world" }) }
|
236
|
+
callback2 = proc {|report| report.add_tab(:significant, { hey: "earth" }) }
|
237
|
+
|
238
|
+
Bugsnag.add_on_error(callback1)
|
239
|
+
Bugsnag.add_on_error(callback2)
|
240
|
+
|
241
|
+
Bugsnag.notify(RuntimeError.new("Oh no!"))
|
242
|
+
|
243
|
+
expect(Bugsnag).to(have_sent_notification do |payload, _headers|
|
244
|
+
event = get_event_from_payload(payload)
|
245
|
+
|
246
|
+
expect(event["metaData"]["important"]).to eq({ "hello" => "world" })
|
247
|
+
expect(event["metaData"]["significant"]).to eq({ "hey" => "earth" })
|
248
|
+
end)
|
249
|
+
end
|
250
|
+
|
251
|
+
describe "using callbacks across threads" do
|
252
|
+
it "runs callbacks that are added in different threads" do
|
253
|
+
callback1 = proc {|report| report.add_tab(:important, { hello: "world" }) }
|
254
|
+
callback2 = proc {|report| report.add_tab(:significant, { hey: "earth" }) }
|
255
|
+
callback3 = proc {|report| report.add_tab(:crucial, { magic_number: 999 }) }
|
256
|
+
|
257
|
+
Bugsnag.add_on_error(callback1)
|
258
|
+
|
259
|
+
threads = [
|
260
|
+
Thread.new { Bugsnag.add_on_error(callback2) },
|
261
|
+
Thread.new { Bugsnag.add_on_error(callback3) }
|
262
|
+
]
|
263
|
+
|
264
|
+
threads.each(&:join)
|
265
|
+
|
266
|
+
Bugsnag.notify(RuntimeError.new("Oh no!"))
|
267
|
+
|
268
|
+
expect(Bugsnag).to(have_sent_notification do |payload, _headers|
|
269
|
+
event = get_event_from_payload(payload)
|
270
|
+
|
271
|
+
expect(event["metaData"]["important"]).to eq({ "hello" => "world" })
|
272
|
+
expect(event["metaData"]["significant"]).to eq({ "hey" => "earth" })
|
273
|
+
expect(event["metaData"]["crucial"]).to eq({ "magic_number" => 999 })
|
274
|
+
end)
|
275
|
+
end
|
276
|
+
|
277
|
+
it "can remove callbacks that are added in different threads" do
|
278
|
+
callback1 = proc {|report| report.add_tab(:important, { hello: "world" }) }
|
279
|
+
callback2 = proc {|report| report.add_tab(:significant, { hey: "earth" }) }
|
280
|
+
|
281
|
+
# We need to create & join these one at a time so that callback1 has
|
282
|
+
# definitely been added before it is removed, otherwise this test will fail
|
283
|
+
# at random
|
284
|
+
Thread.new { Bugsnag.add_on_error(callback1) }.join
|
285
|
+
Thread.new { Bugsnag.remove_on_error(callback1) }.join
|
286
|
+
Thread.new { Bugsnag.add_on_error(callback2) }.join
|
287
|
+
|
288
|
+
Bugsnag.notify(RuntimeError.new("Oh no!"))
|
289
|
+
|
290
|
+
expect(Bugsnag).to(have_sent_notification do |payload, _headers|
|
291
|
+
event = get_event_from_payload(payload)
|
292
|
+
|
293
|
+
expect(event["metaData"]["important"]).to be_nil
|
294
|
+
expect(event["metaData"]["significant"]).to eq({ "hey" => "earth" })
|
295
|
+
end)
|
296
|
+
end
|
297
|
+
|
298
|
+
it "callbacks are called in FIFO order when added in separate threads" do
|
299
|
+
callback1 = proc do |report|
|
300
|
+
expect(report.meta_data[:important]).to be_nil
|
301
|
+
|
302
|
+
report.add_tab(:important, { magic_number: 9 })
|
303
|
+
end
|
304
|
+
|
305
|
+
callback2 = proc do |report|
|
306
|
+
expect(report.meta_data[:important]).to eq({ magic_number: 9 })
|
307
|
+
|
308
|
+
report.add_tab(:important, { magic_number: 99 })
|
309
|
+
end
|
310
|
+
|
311
|
+
callback3 = proc do |report|
|
312
|
+
expect(report.meta_data[:important]).to eq({ magic_number: 99 })
|
313
|
+
|
314
|
+
report.add_tab(:important, { magic_number: 999 })
|
315
|
+
end
|
316
|
+
|
317
|
+
# As above, we need to create & join these one at a time so that each
|
318
|
+
# callback is added in sequence
|
319
|
+
Thread.new { Bugsnag.add_on_error(callback1) }.join
|
320
|
+
Thread.new { Bugsnag.add_on_error(callback2) }.join
|
321
|
+
Thread.new { Bugsnag.add_on_error(callback3) }.join
|
322
|
+
|
323
|
+
Bugsnag.notify(RuntimeError.new("Oh no!"))
|
324
|
+
|
325
|
+
expect(Bugsnag).to(have_sent_notification do |payload, _headers|
|
326
|
+
event = get_event_from_payload(payload)
|
327
|
+
|
328
|
+
expect(event["metaData"]["important"]).to eq({ "magic_number" => 999 })
|
329
|
+
end)
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|