roqua-support 0.1.20 → 0.1.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +32 -33
- data/Guardfile +1 -1
- data/README.md +21 -0
- data/lib/roqua-support/version.rb +1 -1
- data/lib/roqua/support/errors.rb +67 -67
- data/spec/roqua/support/errors_spec.rb +42 -7
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af4e7902bfddd72164acc8f09dce2533316c9471
|
4
|
+
data.tar.gz: e3028ffe08f80d936cfc97d5f6fa901dda1fc5a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03cb1045caf436e5340bd9625a4b2dc9f3208f41c864031c5b0110fb455933d84fd26d5ec414c47137593b2bc82077adcc8456525cf1ca7f73f3fae669391615
|
7
|
+
data.tar.gz: 761670d36d6e992f063209e1f946065df4d2e1a792da65074645588fcb7de727d0f630308af60a693bed12731ffedbb4918999386999675706a8e95cfa39c98e
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
roqua-support (0.1.
|
4
|
+
roqua-support (0.1.21)
|
5
5
|
activesupport (>= 3.2, < 5.0)
|
6
6
|
naught (~> 1.0)
|
7
7
|
|
@@ -40,9 +40,6 @@ GEM
|
|
40
40
|
erubis (2.7.0)
|
41
41
|
ffi (1.9.6)
|
42
42
|
formatador (0.2.5)
|
43
|
-
fuubar (1.3.3)
|
44
|
-
rspec (>= 2.14.0, < 3.1.0)
|
45
|
-
ruby-progressbar (~> 1.4)
|
46
43
|
guard (2.7.0)
|
47
44
|
formatador (>= 0.2.4)
|
48
45
|
listen (~> 2.7)
|
@@ -53,59 +50,59 @@ GEM
|
|
53
50
|
guard (~> 2.1)
|
54
51
|
rspec (>= 2.14, < 4.0)
|
55
52
|
hitimes (1.2.2)
|
56
|
-
i18n (0.
|
57
|
-
json (1.8.
|
53
|
+
i18n (0.7.0)
|
54
|
+
json (1.8.3)
|
58
55
|
listen (2.7.11)
|
59
56
|
celluloid (>= 0.15.2)
|
60
57
|
rb-fsevent (>= 0.9.3)
|
61
58
|
rb-inotify (>= 0.9)
|
62
59
|
lumberjack (1.0.9)
|
63
60
|
method_source (0.8.2)
|
64
|
-
minitest (5.
|
65
|
-
naught (1.
|
61
|
+
minitest (5.9.0)
|
62
|
+
naught (1.1.0)
|
66
63
|
pry (0.10.1)
|
67
64
|
coderay (~> 1.1.0)
|
68
65
|
method_source (~> 0.8.1)
|
69
66
|
slop (~> 3.4)
|
70
|
-
rack (1.5.
|
71
|
-
rack-test (0.6.
|
67
|
+
rack (1.5.5)
|
68
|
+
rack-test (0.6.3)
|
72
69
|
rack (>= 1.0)
|
73
70
|
railties (4.1.6)
|
74
71
|
actionpack (= 4.1.6)
|
75
72
|
activesupport (= 4.1.6)
|
76
73
|
rake (>= 0.8.7)
|
77
74
|
thor (>= 0.18.1, < 2.0)
|
78
|
-
rake (
|
75
|
+
rake (11.2.2)
|
79
76
|
rb-fsevent (0.9.4)
|
80
77
|
rb-inotify (0.9.5)
|
81
78
|
ffi (>= 0.5.0)
|
82
|
-
rspec (3.
|
83
|
-
rspec-core (~> 3.
|
84
|
-
rspec-expectations (~> 3.
|
85
|
-
rspec-mocks (~> 3.
|
86
|
-
rspec-core (3.
|
87
|
-
rspec-support (~> 3.
|
88
|
-
rspec-expectations (3.0
|
79
|
+
rspec (3.4.0)
|
80
|
+
rspec-core (~> 3.4.0)
|
81
|
+
rspec-expectations (~> 3.4.0)
|
82
|
+
rspec-mocks (~> 3.4.0)
|
83
|
+
rspec-core (3.4.4)
|
84
|
+
rspec-support (~> 3.4.0)
|
85
|
+
rspec-expectations (3.4.0)
|
89
86
|
diff-lcs (>= 1.2.0, < 2.0)
|
90
|
-
rspec-support (~> 3.
|
87
|
+
rspec-support (~> 3.4.0)
|
91
88
|
rspec-instrumentation-matcher (0.0.4)
|
92
89
|
activesupport
|
93
90
|
rspec-expectations
|
94
|
-
rspec-mocks (3.
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
rspec-
|
102
|
-
rspec-
|
103
|
-
rspec-
|
104
|
-
|
105
|
-
|
91
|
+
rspec-mocks (3.4.1)
|
92
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
93
|
+
rspec-support (~> 3.4.0)
|
94
|
+
rspec-rails (3.4.2)
|
95
|
+
actionpack (>= 3.0, < 4.3)
|
96
|
+
activesupport (>= 3.0, < 4.3)
|
97
|
+
railties (>= 3.0, < 4.3)
|
98
|
+
rspec-core (~> 3.4.0)
|
99
|
+
rspec-expectations (~> 3.4.0)
|
100
|
+
rspec-mocks (~> 3.4.0)
|
101
|
+
rspec-support (~> 3.4.0)
|
102
|
+
rspec-support (3.4.1)
|
106
103
|
slop (3.6.0)
|
107
104
|
thor (0.19.1)
|
108
|
-
thread_safe (0.3.
|
105
|
+
thread_safe (0.3.5)
|
109
106
|
timers (4.0.1)
|
110
107
|
hitimes
|
111
108
|
tzinfo (1.2.2)
|
@@ -119,10 +116,12 @@ DEPENDENCIES
|
|
119
116
|
active_interaction (~> 1.0)
|
120
117
|
bundler (~> 1.0)
|
121
118
|
combustion (~> 0.5.2)
|
122
|
-
fuubar (~> 1.3.2)
|
123
119
|
guard-rspec (~> 4.2.6)
|
124
120
|
rake
|
125
121
|
roqua-support!
|
126
122
|
rspec (>= 2.12.0, < 4.0)
|
127
123
|
rspec-instrumentation-matcher
|
128
124
|
rspec-rails
|
125
|
+
|
126
|
+
BUNDLED WITH
|
127
|
+
1.12.5
|
data/Guardfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# A sample Guardfile
|
2
2
|
# More info at https://github.com/guard/guard#readme
|
3
3
|
|
4
|
-
guard :rspec, cmd: 'bundle exec rspec --
|
4
|
+
guard :rspec, cmd: 'bundle exec rspec --colour' do
|
5
5
|
watch(%r{^spec/.+_spec\.rb$})
|
6
6
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
7
|
watch('spec/spec_helper.rb') { "spec" }
|
data/README.md
CHANGED
@@ -48,6 +48,27 @@ require 'roqua/support/request_logger'
|
|
48
48
|
Roqua::Support::RequestLogger.attach_to :action_controller
|
49
49
|
```
|
50
50
|
|
51
|
+
### Error reporting
|
52
|
+
|
53
|
+
Log and error to Roqua.logger, appsignal and/or airbrake, depending on which is configured.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
Roqua::Support::Errors.report(exception, extra: 'params')
|
57
|
+
```
|
58
|
+
|
59
|
+
Add extra info to all reports (global setting, put in initializer)
|
60
|
+
|
61
|
+
```
|
62
|
+
Roqua::Support::Errors.extra_parameters = {root_path: Rails.root.to_s}
|
63
|
+
```
|
64
|
+
|
65
|
+
When you want to add more info, but want to catch the error higher up you can call Errors.add_parameters, which will save them on the current exception instance.
|
66
|
+
|
67
|
+
```
|
68
|
+
rescue
|
69
|
+
raise Roqua::Support::Errors::add_parameters(more: 'params')
|
70
|
+
```
|
71
|
+
|
51
72
|
### Responders
|
52
73
|
|
53
74
|
#### option 1
|
data/lib/roqua/support/errors.rb
CHANGED
@@ -1,107 +1,107 @@
|
|
1
1
|
module Roqua
|
2
2
|
module Support
|
3
3
|
module Errors
|
4
|
+
# global extra parameters to be added to all reports.
|
4
5
|
def self.extra_parameters
|
5
6
|
@extra_parameters || {}
|
6
7
|
end
|
7
8
|
|
8
9
|
def self.extra_parameters=(hash)
|
10
|
+
fail 'not a hash' unless hash.is_a? Hash
|
9
11
|
@extra_parameters = hash
|
10
12
|
end
|
11
13
|
|
14
|
+
# adds instance variable roqua_extra_parameters to current exception.
|
15
|
+
def self.add_parameters(params)
|
16
|
+
return unless params.is_a?(Hash) && $!
|
17
|
+
$!.instance_eval do
|
18
|
+
(@roqua_extra_parameters ||= {}).merge! params
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
12
22
|
def self.report(exception, context = {})
|
13
23
|
return if const_defined?(:Rails) and Rails.env.test?
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
24
|
+
context = {} unless context.is_a? Hash
|
25
|
+
|
26
|
+
parameters, controller, skip_backtrace = merge_parameters(exception, context)
|
27
|
+
|
28
|
+
notification_urls = [notify_airbrake(exception, controller, parameters),
|
29
|
+
notify_appsignal(exception, parameters)]
|
20
30
|
# Notify Roqua logging
|
21
31
|
log_exception(exception, parameters, notification_urls.compact, skip_backtrace)
|
22
32
|
end
|
23
33
|
|
24
34
|
private
|
25
35
|
|
26
|
-
def self.merge_parameters(context)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
[parameters, controller, skip_backtrace]
|
40
|
-
rescue Exception
|
41
|
-
end
|
36
|
+
def self.merge_parameters(exception, context = {})
|
37
|
+
parameters = extra_parameters.dup
|
38
|
+
controller = context.delete :controller
|
39
|
+
skip_backtrace = context.delete :skip_backtrace
|
40
|
+
parameters.merge! context
|
41
|
+
parameters.merge! extra_parameters_from_exception(exception)
|
42
|
+
[parameters, controller, skip_backtrace]
|
43
|
+
rescue Exception
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.extra_parameters_from_exception(exception)
|
47
|
+
exception.instance_variable_get(:@roqua_extra_parameters) || {}
|
42
48
|
end
|
43
49
|
|
44
50
|
def self.log_exception(exception, parameters = {}, notification_urls = [], skip_backtrace = false)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
Roqua.logger.error('roqua.exception', exception_info)
|
54
|
-
end
|
55
|
-
rescue Exception
|
51
|
+
if Roqua.respond_to?(:logger)
|
52
|
+
exception_info = {class_name: exception.class.to_s,
|
53
|
+
message: exception.message,
|
54
|
+
parameters: parameters}
|
55
|
+
exception_info[:notification_urls] = notification_urls if notification_urls.present?
|
56
|
+
exception_info[:backtrace] = exception.backtrace unless skip_backtrace
|
57
|
+
puts exception_info.inspect
|
58
|
+
Roqua.logger.error('roqua.exception', exception_info)
|
56
59
|
end
|
60
|
+
rescue Exception
|
57
61
|
end
|
58
62
|
|
59
63
|
def self.notify_airbrake(exception, controller, parameters = {})
|
60
|
-
|
61
|
-
if
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
request_data[:parameters] = parameters.merge request_data[:parameters]
|
68
|
-
end
|
69
|
-
else
|
70
|
-
request_data = nil
|
64
|
+
if const_defined?(:Airbrake)
|
65
|
+
if controller && controller.respond_to?(:airbrake_request_data)
|
66
|
+
request_data = controller.airbrake_request_data
|
67
|
+
if request_data.is_a?(Hash)
|
68
|
+
request_data[:parameters] ||= {}
|
69
|
+
if request_data[:parameters].is_a?(Hash)
|
70
|
+
request_data[:parameters] = parameters.merge request_data[:parameters]
|
71
71
|
end
|
72
|
+
else
|
73
|
+
request_data = nil
|
72
74
|
end
|
73
|
-
request_data ||= {parameters: parameters}
|
74
|
-
uuid = Airbrake.notify_or_ignore(exception, request_data)
|
75
|
-
"https://airbrake.io/locate/#{uuid}" if uuid
|
76
75
|
end
|
77
|
-
|
76
|
+
request_data ||= {parameters: parameters}
|
77
|
+
uuid = Airbrake.notify_or_ignore(exception, request_data)
|
78
|
+
"https://airbrake.io/locate/#{uuid}" if uuid
|
78
79
|
end
|
80
|
+
rescue Exception
|
79
81
|
end
|
80
82
|
|
81
83
|
def self.notify_appsignal(exception, parameters = {})
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
# Appsignal.send_exception(exception, parameters: parameters)
|
84
|
+
if const_defined?(:Appsignal) and
|
85
|
+
not Appsignal.is_ignored_exception?(exception)
|
86
|
+
# TODO: If and when https://github.com/appsignal/appsignal/pull/9 is merged,
|
87
|
+
# this functionality should be supported directly by Appsignal.send_exception.
|
88
|
+
# Appsignal.send_exception(exception, parameters: parameters)
|
88
89
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
90
|
+
if Appsignal.active?
|
91
|
+
# Hackety hack around stateful mess of Appsignal gem
|
92
|
+
if Appsignal::Transaction.current
|
93
|
+
Appsignal::Transaction.current.set_tags(parameters)
|
94
|
+
Appsignal::Transaction.current.add_exception(exception)
|
95
|
+
else
|
96
|
+
transaction = Appsignal::Transaction.create(SecureRandom.uuid, ENV.to_hash)
|
97
|
+
transaction.set_tags(parameters)
|
98
|
+
transaction.add_exception(exception)
|
99
|
+
transaction.complete!
|
100
|
+
Appsignal.agent.send_queue
|
101
101
|
end
|
102
102
|
end
|
103
|
-
rescue Exception
|
104
103
|
end
|
104
|
+
rescue Exception
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
@@ -45,6 +45,48 @@ describe 'Error reporting' do
|
|
45
45
|
Roqua::Support::Errors.report exception, skip_backtrace: true
|
46
46
|
end
|
47
47
|
|
48
|
+
it 'can add extra parameters by calling add_parameters' do
|
49
|
+
Roqua.logger.should_receive(:error).with \
|
50
|
+
'roqua.exception', class_name: 'RuntimeError',
|
51
|
+
message: 'exception_message',
|
52
|
+
parameters: {more: 'params',
|
53
|
+
even_more: 'params'}
|
54
|
+
begin
|
55
|
+
begin
|
56
|
+
begin
|
57
|
+
fail 'exception_message'
|
58
|
+
rescue
|
59
|
+
Roqua::Support::Errors.add_parameters(more: 'params')
|
60
|
+
raise
|
61
|
+
end
|
62
|
+
rescue
|
63
|
+
Roqua::Support::Errors.add_parameters(even_more: 'params')
|
64
|
+
raise
|
65
|
+
end
|
66
|
+
rescue => e
|
67
|
+
Roqua::Support::Errors.report e, skip_backtrace: true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'will not fail when called outside of rescue or when passed the wrong format to add_parameters' do
|
72
|
+
Roqua.logger.should_receive(:error).with \
|
73
|
+
'roqua.exception', class_name: 'RuntimeError',
|
74
|
+
message: 'exception_message',
|
75
|
+
parameters: {}
|
76
|
+
|
77
|
+
begin
|
78
|
+
Roqua::Support::Errors.add_parameters('just a string')
|
79
|
+
begin
|
80
|
+
fail 'exception_message'
|
81
|
+
rescue
|
82
|
+
Roqua::Support::Errors.add_parameters('just a string')
|
83
|
+
raise
|
84
|
+
end
|
85
|
+
rescue => e
|
86
|
+
Roqua::Support::Errors.report e, skip_backtrace: true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
48
90
|
it 'logs notification_urls when present' do
|
49
91
|
stub_const('Airbrake', double('Airbrake', notify_or_ignore: 'uuid'))
|
50
92
|
Roqua.logger.should_receive(:error)
|
@@ -75,13 +117,6 @@ describe 'Error reporting' do
|
|
75
117
|
Roqua::Support::Errors.report exception, controller: controller, some: 'context'
|
76
118
|
end
|
77
119
|
|
78
|
-
it 'does not fail with extra parameters of incompatible type' do
|
79
|
-
Roqua::Support::Errors.extra_parameters = ['extra', 'param']
|
80
|
-
expect(Airbrake).to receive(:notify_or_ignore).with(exception, parameters: {})
|
81
|
-
Roqua::Support::Errors.report exception
|
82
|
-
Roqua::Support::Errors.extra_parameters = {}
|
83
|
-
end
|
84
|
-
|
85
120
|
it 'does not fail with context of incompatible type' do
|
86
121
|
expect(Airbrake).to receive(:notify_or_ignore).with(exception, parameters: {})
|
87
122
|
Roqua::Support::Errors.report exception, ['controller', 'extra_param']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roqua-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marten Veldthuis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
171
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
172
|
+
rubygems_version: 2.5.1
|
173
173
|
signing_key:
|
174
174
|
specification_version: 4
|
175
175
|
summary: Helper objects and proxies used by a lot of RoQua applications
|
@@ -192,4 +192,3 @@ test_files:
|
|
192
192
|
- spec/roqua/support_spec.rb
|
193
193
|
- spec/roqua/validators/subset_validator_spec.rb
|
194
194
|
- spec/spec_helper.rb
|
195
|
-
has_rdoc:
|