action_subscriber 4.4.0 → 4.5.0.pre0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/action_subscriber/configuration.rb +7 -1
- data/lib/action_subscriber/middleware/error_handler.rb +11 -18
- data/lib/action_subscriber/version.rb +1 -1
- data/spec/lib/action_subscriber/configuration_spec.rb +17 -0
- data/spec/lib/action_subscriber/middleware/error_handler_spec.rb +0 -15
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ff445afc60cb441e3af5c2e9e65f13826fa02d8
|
4
|
+
data.tar.gz: 5346ff383fa7ebd1b0047cd9d5392e30ce492d4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52b19ec1002942aa27c185aee22ec1a13d8e9ec1db7648db4c04621e8d3a8baa6aa66d82c7dcf6dcb6d1d5843f23e48ffe4d80c318004b256216c5695ef9861b
|
7
|
+
data.tar.gz: 13b671f299f909e1f05b8e81dc26c9f8be8957d511ab79d6fed98d5c3ba2b77c6b5337356d98d1e4af600dc6bf9be7ff661fc29e5cb1ee15ba6530f7c543758a
|
@@ -85,7 +85,13 @@ module ActionSubscriber
|
|
85
85
|
'text/plain' => lambda { |payload| payload.dup }
|
86
86
|
}
|
87
87
|
|
88
|
-
self.error_handler = lambda
|
88
|
+
self.error_handler = lambda do |error, env_hash|
|
89
|
+
logger = ::ActionSubscriber::Logging.logger
|
90
|
+
|
91
|
+
logger.error(error.message)
|
92
|
+
logger.error(error.class.to_s)
|
93
|
+
logger.error(error.backtrace.join("\n")) if error.try(:backtrace) && error.backtrace.is_a?(::Array)
|
94
|
+
end
|
89
95
|
|
90
96
|
DEFAULTS.each_pair do |key, value|
|
91
97
|
self.__send__("#{key}=", value)
|
@@ -8,25 +8,18 @@ module ActionSubscriber
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(env)
|
11
|
-
|
12
|
-
|
11
|
+
@app.call(env)
|
12
|
+
rescue => error
|
13
|
+
logger.error "FAILED #{env.message_id}"
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
ensure
|
23
|
-
job_complete.signal
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# TODO we might want to pass a timeout to this wait so we can handle jobs that get frozen
|
29
|
-
job_complete.wait(job_mutex)
|
15
|
+
# There is more to this rescue than meets the eye. MarchHare's java library will rescue errors
|
16
|
+
# and attempt to close the channel with its default exception handler. To avoid this, we will
|
17
|
+
# stop errors right here. If you want to handle errors, you must do it in the error handler and
|
18
|
+
# it should not re-raise. As a bonus, not killing these threads is better for your runtime :).
|
19
|
+
begin
|
20
|
+
::ActionSubscriber.configuration.error_handler.call(error, env.to_h)
|
21
|
+
rescue => error
|
22
|
+
logger.error "ActionSubscriber error handler raised error, but should never raise. Error: #{error}"
|
30
23
|
end
|
31
24
|
end
|
32
25
|
end
|
@@ -43,4 +43,21 @@ describe ::ActionSubscriber::Configuration do
|
|
43
43
|
expect(subject.virtual_host).to eq("vhost")
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
describe "error_handler" do
|
48
|
+
let(:logger) { ::ActionSubscriber::Logging.logger }
|
49
|
+
|
50
|
+
it "by default logs the error" do
|
51
|
+
expect(logger).to receive(:error).with("I'm confused")
|
52
|
+
expect(logger).to receive(:error).with("ArgumentError")
|
53
|
+
# Lame way of looking for the backtrace.
|
54
|
+
expect(logger).to receive(:error).with(/\.rb/)
|
55
|
+
|
56
|
+
begin
|
57
|
+
fail ::ArgumentError, "I'm confused"
|
58
|
+
rescue => error
|
59
|
+
subject.error_handler.call(error, {})
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
46
63
|
end
|
@@ -19,19 +19,4 @@ describe ActionSubscriber::Middleware::ErrorHandler do
|
|
19
19
|
subject.call(env)
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
23
|
-
context "many concurrent threads" do
|
24
|
-
it "handles the race conditions without raising exceptions" do
|
25
|
-
no_op = lambda{ nil }
|
26
|
-
threads = 1.upto(100).map do
|
27
|
-
::Thread.new do
|
28
|
-
::Thread.current.abort_on_exception = true
|
29
|
-
100.times do
|
30
|
-
described_class.new(no_op).call(env)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
threads.each(&:join)
|
35
|
-
end
|
36
|
-
end
|
37
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_subscriber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.5.0.pre0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Stien
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2017-
|
15
|
+
date: 2017-08-09 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activesupport
|
@@ -277,9 +277,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
277
277
|
version: '0'
|
278
278
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
279
279
|
requirements:
|
280
|
-
- - "
|
280
|
+
- - ">"
|
281
281
|
- !ruby/object:Gem::Version
|
282
|
-
version:
|
282
|
+
version: 1.3.1
|
283
283
|
requirements: []
|
284
284
|
rubyforge_project:
|
285
285
|
rubygems_version: 2.5.2
|