exception_handling 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f044af7181eaef68a7eb2256d23d600c4a00e40a
4
+ data.tar.gz: 68e5bb626894789472c54d2cb3013f93420ea0aa
5
+ SHA512:
6
+ metadata.gz: 4669ab83c2a33f593522f035ff2c79374bd515aea0b7e1499ed3c2027a1ef899a6bae41813bb7184324b292eddbb6160f68399799d0f19b119be5df537f3c124
7
+ data.tar.gz: cbe924a30ee2899b16e8c83e5625042c6547c6c476527c0c15c66b5679d22dafac6e40d993218a0e2440e854513e44913b3cc08dfa45e87c5dd7dcd0f0e56da6
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p247
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- exception_handling (0.1.1)
4
+ exception_handling (0.1.2)
5
5
  actionmailer (= 3.2.13)
6
6
  actionpack (= 3.2.13)
7
7
  activesupport (= 3.2.13)
@@ -41,7 +41,7 @@ GEM
41
41
  mime-types (~> 1.16)
42
42
  treetop (~> 1.4.8)
43
43
  metaclass (0.0.1)
44
- mime-types (1.24)
44
+ mime-types (1.25.1)
45
45
  mocha (0.13.0)
46
46
  metaclass (~> 0.0.1)
47
47
  multi_json (1.7.8)
@@ -1,3 +1,3 @@
1
1
  module ExceptionHandling
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -209,6 +209,14 @@ EOF
209
209
  return nil
210
210
  end
211
211
 
212
+ def ensure_completely_safe( exception_context = "" )
213
+ yield
214
+ rescue SystemExit, SystemStackError, NoMemoryError, SecurityError, SignalException
215
+ raise
216
+ rescue Exception => ex
217
+ log_error ex, exception_context
218
+ end
219
+
212
220
  def ensure_escalation( email_subject )
213
221
  begin
214
222
  yield
@@ -178,41 +178,94 @@ end
178
178
  end
179
179
  end
180
180
 
181
- context "ExceptionHandling::ensure_safe" do
181
+ context "ExceptionHandling.ensure_safe" do
182
182
  should "log an exception if an exception is raised." do
183
183
  ExceptionHandling.logger.expects(:fatal).with( ) { |ex| ex =~ /\(blah\):\n.*exception_handling_test\.rb/ or raise "Unexpected: #{ex.inspect}" }
184
- ExceptionHandling::ensure_safe { raise ArgumentError.new("blah") }
184
+ ExceptionHandling.ensure_safe { raise ArgumentError.new("blah") }
185
185
  end
186
186
 
187
187
  should "should not log an exception if an exception is not raised." do
188
188
  ExceptionHandling.logger.expects(:fatal).never
189
- ExceptionHandling::ensure_safe { ; }
189
+ ExceptionHandling.ensure_safe { ; }
190
190
  end
191
191
 
192
192
  should "return its value if used during an assignment" do
193
193
  ExceptionHandling.logger.expects(:fatal).never
194
- b = ExceptionHandling::ensure_safe { 5 }
194
+ b = ExceptionHandling.ensure_safe { 5 }
195
195
  assert_equal 5, b
196
196
  end
197
197
 
198
198
  should "return nil if an exception is raised during an assignment" do
199
199
  ExceptionHandling.logger.expects(:fatal).returns(nil)
200
- b = ExceptionHandling::ensure_safe { raise ArgumentError.new("blah") }
200
+ b = ExceptionHandling.ensure_safe { raise ArgumentError.new("blah") }
201
201
  assert_equal nil, b
202
202
  end
203
203
 
204
204
  should "allow a message to be appended to the error when logged." do
205
205
  ExceptionHandling.logger.expects(:fatal).with( ) { |ex| ex =~ /mooo \(blah\):\n.*exception_handling_test\.rb/ or raise "Unexpected: #{ex.inspect}" }
206
- b = ExceptionHandling::ensure_safe("mooo") { raise ArgumentError.new("blah") }
206
+ b = ExceptionHandling.ensure_safe("mooo") { raise ArgumentError.new("blah") }
207
207
  assert_nil b
208
208
  end
209
+
210
+ should "only rescue StandardError and descendents" do
211
+ assert_raise(Exception) { ExceptionHandling.ensure_safe("mooo") { raise Exception } }
212
+
213
+ ExceptionHandling.logger.expects(:fatal).with( ) { |ex| ex =~ /mooo \(blah\):\n.*exception_handling_test\.rb/ or raise "Unexpected: #{ex.inspect}" }
214
+ b = ExceptionHandling.ensure_safe("mooo") { raise StandardError.new("blah") }
215
+ assert_nil b
216
+ end
217
+ end
218
+
219
+ context "ExceptionHandling.ensure_completely_safe" do
220
+ should "log an exception if an exception is raised." do
221
+ ExceptionHandling.logger.expects(:fatal).with( ) { |ex| ex =~ /\(blah\):\n.*exception_handling_test\.rb/ or raise "Unexpected: #{ex.inspect}" }
222
+ ExceptionHandling.ensure_completely_safe { raise ArgumentError.new("blah") }
223
+ end
224
+
225
+ should "should not log an exception if an exception is not raised." do
226
+ ExceptionHandling.logger.expects(:fatal).never
227
+ ExceptionHandling.ensure_completely_safe { ; }
228
+ end
229
+
230
+ should "return its value if used during an assignment" do
231
+ ExceptionHandling.logger.expects(:fatal).never
232
+ b = ExceptionHandling.ensure_completely_safe { 5 }
233
+ assert_equal 5, b
234
+ end
235
+
236
+ should "return nil if an exception is raised during an assignment" do
237
+ ExceptionHandling.logger.expects(:fatal).returns(nil)
238
+ b = ExceptionHandling.ensure_completely_safe { raise ArgumentError.new("blah") }
239
+ assert_equal nil, b
240
+ end
241
+
242
+ should "allow a message to be appended to the error when logged." do
243
+ ExceptionHandling.logger.expects(:fatal).with( ) { |ex| ex =~ /mooo \(blah\):\n.*exception_handling_test\.rb/ or raise "Unexpected: #{ex.inspect}" }
244
+ b = ExceptionHandling.ensure_completely_safe("mooo") { raise ArgumentError.new("blah") }
245
+ assert_nil b
246
+ end
247
+
248
+ should "rescue any instance or child of Exception" do
249
+ ExceptionHandling.logger.expects(:fatal).with( ) { |ex| ex =~ /\(blah\):\n.*exception_handling_test\.rb/ or raise "Unexpected: #{ex.inspect}" }
250
+ ExceptionHandling::ensure_completely_safe { raise Exception.new("blah") }
251
+ end
252
+
253
+ should "not rescue the special exceptions that Ruby uses" do
254
+ [SystemExit, SystemStackError, NoMemoryError, SecurityError].each do |exception|
255
+ assert_raise exception do
256
+ ExceptionHandling.ensure_completely_safe do
257
+ raise exception.new
258
+ end
259
+ end
260
+ end
261
+ end
209
262
  end
210
263
 
211
- context "ExceptionHandling::ensure_escalation" do
264
+ context "ExceptionHandling.ensure_escalation" do
212
265
  should "log the exception as usual and send the proper email" do
213
266
  assert_equal 0, ActionMailer::Base.deliveries.count
214
267
  ExceptionHandling.logger.expects(:fatal).with( ) { |ex| ex =~ /\(blah\):\n.*exception_handling_test\.rb/ or raise "Unexpected: #{ex.inspect}" }
215
- ExceptionHandling::ensure_escalation( "Favorite Feature") { raise ArgumentError.new("blah") }
268
+ ExceptionHandling.ensure_escalation( "Favorite Feature") { raise ArgumentError.new("blah") }
216
269
  assert_equal 2, ActionMailer::Base.deliveries.count
217
270
  email = ActionMailer::Base.deliveries.last
218
271
  assert_equal 'test Escalation: Favorite Feature', email.subject
@@ -223,7 +276,7 @@ end
223
276
  should "should not escalate if an exception is not raised." do
224
277
  assert_equal 0, ActionMailer::Base.deliveries.count
225
278
  ExceptionHandling.logger.expects(:fatal).never
226
- ExceptionHandling::ensure_escalation('Ignored') { ; }
279
+ ExceptionHandling.ensure_escalation('Ignored') { ; }
227
280
  assert_equal 0, ActionMailer::Base.deliveries.count
228
281
  end
229
282
 
@@ -234,7 +287,7 @@ end
234
287
 
235
288
  $stderr.stubs(:puts)
236
289
  ExceptionHandling.logger.expects(:fatal).times(2).with { |ex| ex =~ exception_regexs[exception_count] or raise "Unexpected [#{exception_count}]: #{ex.inspect}"; exception_count += 1; true }
237
- ExceptionHandling::ensure_escalation("Not Used") { raise ArgumentError.new("first_test_exception") }
290
+ ExceptionHandling.ensure_escalation("Not Used") { raise ArgumentError.new("first_test_exception") }
238
291
  #assert_equal 0, ActionMailer::Base.deliveries.count
239
292
  end
240
293
  end
@@ -246,7 +299,7 @@ end
246
299
 
247
300
  should "include the timestamp when the exception is logged" do
248
301
  ExceptionHandling.logger.expects(:fatal).with { |ex| ex =~ /\(Error:517033020\) ArgumentError mooo \(blah\):\n.*exception_handling_test\.rb/ or raise "Unexpected: #{ex.inspect}" }
249
- b = ExceptionHandling::ensure_safe("mooo") { raise ArgumentError.new("blah") }
302
+ b = ExceptionHandling.ensure_safe("mooo") { raise ArgumentError.new("blah") }
250
303
  assert_nil b
251
304
 
252
305
  assert_equal 517033020, ExceptionHandling.last_exception_timestamp
@@ -732,20 +785,20 @@ end
732
785
  end
733
786
  end
734
787
 
735
- context "ExceptionHandling::log_error" do
788
+ context "ExceptionHandling.log_error" do
736
789
  should "log errors" do
737
790
  ExceptionHandling.logger.expects(:fatal).with( ) { |ex| ex =~ /\(blah\):\n.*exception_handling_test\.rb/ or raise "Unexpected: #{ex.inspect}" }
738
- ExceptionHandling::log_error( @argument_error )
791
+ ExceptionHandling.log_error( @argument_error )
739
792
  end
740
793
 
741
794
  should "log errors from strings" do
742
795
  ExceptionHandling.logger.expects(:fatal).with( ) { |ex| ex =~ /\(blah\):\n.*exception_handling\.rb/ or raise "Unexpected: #{ex.inspect}" }
743
- ExceptionHandling::log_error( "blah" )
796
+ ExceptionHandling.log_error( "blah" )
744
797
  end
745
798
 
746
799
  should "log errors with strings" do
747
800
  ExceptionHandling.logger.expects(:fatal).with( ) { |ex| ex =~ /mooo.*\(blah\):\n.*exception_handling_test\.rb/ or raise "Unexpected: #{ex.inspect}" }
748
- ExceptionHandling::log_error( @argument_error, "mooo" )
801
+ ExceptionHandling.log_error( @argument_error, "mooo" )
749
802
  end
750
803
  end
751
804
  end
metadata CHANGED
@@ -1,130 +1,122 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: exception_handling
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Colin Kelley
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2013-08-26 00:00:00 -07:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- type: :runtime
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- segments:
27
- - 0
28
- - 12
29
- - 10
30
- version: 0.12.10
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
31
14
  name: eventmachine
32
- requirement: *id001
33
- prerelease: false
34
- - !ruby/object:Gem::Dependency
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.10
35
20
  type: :runtime
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "="
39
- - !ruby/object:Gem::Version
40
- segments:
41
- - 3
42
- - 2
43
- - 13
44
- version: 3.2.13
45
- name: activesupport
46
- requirement: *id002
47
21
  prerelease: false
48
- - !ruby/object:Gem::Dependency
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.2.13
49
34
  type: :runtime
50
- version_requirements: &id003 !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "="
53
- - !ruby/object:Gem::Version
54
- segments:
55
- - 3
56
- - 2
57
- - 13
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
58
40
  version: 3.2.13
41
+ - !ruby/object:Gem::Dependency
59
42
  name: actionpack
60
- requirement: *id003
61
- prerelease: false
62
- - !ruby/object:Gem::Dependency
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.13
63
48
  type: :runtime
64
- version_requirements: &id004 !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "="
67
- - !ruby/object:Gem::Version
68
- segments:
69
- - 3
70
- - 2
71
- - 13
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
72
54
  version: 3.2.13
55
+ - !ruby/object:Gem::Dependency
73
56
  name: actionmailer
74
- requirement: *id004
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.13
62
+ type: :runtime
75
63
  prerelease: false
76
- - !ruby/object:Gem::Dependency
77
- type: :development
78
- version_requirements: &id005 !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- segments:
83
- - 0
84
- - 9
85
- version: "0.9"
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.13
69
+ - !ruby/object:Gem::Dependency
86
70
  name: rake
87
- requirement: *id005
88
- prerelease: false
89
- - !ruby/object:Gem::Dependency
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
90
76
  type: :development
91
- version_requirements: &id006 !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "="
94
- - !ruby/object:Gem::Version
95
- segments:
96
- - 3
97
- - 1
98
- - 1
99
- version: 3.1.1
100
- name: shoulda
101
- requirement: *id006
102
77
  prerelease: false
103
- - !ruby/object:Gem::Dependency
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: shoulda
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 3.1.1
104
90
  type: :development
105
- version_requirements: &id007 !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "="
108
- - !ruby/object:Gem::Version
109
- segments:
110
- - 0
111
- - 13
112
- - 0
113
- version: 0.13.0
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 3.1.1
97
+ - !ruby/object:Gem::Dependency
114
98
  name: mocha
115
- requirement: *id007
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.13.0
104
+ type: :development
116
105
  prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.13.0
117
111
  description: Exception handling logger/emailer
118
- email:
112
+ email:
119
113
  - colindkelley@gmail.com
120
114
  executables: []
121
-
122
115
  extensions: []
123
-
124
116
  extra_rdoc_files: []
125
-
126
- files:
117
+ files:
127
118
  - .gitignore
119
+ - .ruby-version
128
120
  - Gemfile
129
121
  - Gemfile.lock
130
122
  - LICENSE
@@ -141,37 +133,31 @@ files:
141
133
  - views/exception_handling/mailer/escalation_notification.html.erb
142
134
  - views/exception_handling/mailer/exception_notification.html.erb
143
135
  - views/exception_handling/mailer/log_parser_exception_notification.html.erb
144
- has_rdoc: true
145
136
  homepage: https://github.com/RingRevenue/exception_handling
146
137
  licenses: []
147
-
138
+ metadata: {}
148
139
  post_install_message:
149
140
  rdoc_options: []
150
-
151
- require_paths:
141
+ require_paths:
152
142
  - lib
153
- required_ruby_version: !ruby/object:Gem::Requirement
154
- requirements:
155
- - - ">="
156
- - !ruby/object:Gem::Version
157
- segments:
158
- - 0
159
- version: "0"
160
- required_rubygems_version: !ruby/object:Gem::Requirement
161
- requirements:
162
- - - ">="
163
- - !ruby/object:Gem::Version
164
- segments:
165
- - 0
166
- version: "0"
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
167
153
  requirements: []
168
-
169
154
  rubyforge_project:
170
- rubygems_version: 1.3.6
155
+ rubygems_version: 2.0.3
171
156
  signing_key:
172
- specification_version: 3
173
- summary: RingRevenue's exception handling logger/emailer layer, based on exception_notifier. Works with Rails or EventMachine or EventMachine+Synchrony.
174
- test_files:
157
+ specification_version: 4
158
+ summary: RingRevenue's exception handling logger/emailer layer, based on exception_notifier.
159
+ Works with Rails or EventMachine or EventMachine+Synchrony.
160
+ test_files:
175
161
  - test/exception_handling_test.rb
176
162
  - test/mocha_patch.rb
177
163
  - test/test_helper.rb