enhanced_errors 2.1.1 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardoc/checksums +1 -1
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/doc/Enhanced/Colors.html +2 -2
- data/doc/Enhanced.html +2 -2
- data/doc/EnhancedErrors.html +404 -291
- data/doc/Exception.html +2 -2
- data/doc/Minitest.html +2 -2
- data/doc/_index.html +2 -2
- data/doc/file.README.html +3 -3
- data/doc/index.html +3 -3
- data/doc/method_list.html +43 -27
- data/doc/top-level-namespace.html +2 -2
- data/enhanced_errors.gemspec +1 -1
- data/lib/enhanced_errors.rb +90 -87
- metadata +2 -2
data/doc/Exception.html
CHANGED
@@ -241,9 +241,9 @@
|
|
241
241
|
</div>
|
242
242
|
|
243
243
|
<div id="footer">
|
244
|
-
Generated on
|
244
|
+
Generated on Mon Dec 16 10:41:42 2024 by
|
245
245
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
246
|
-
0.9.37 (ruby-3.
|
246
|
+
0.9.37 (ruby-3.3.6).
|
247
247
|
</div>
|
248
248
|
|
249
249
|
</div>
|
data/doc/Minitest.html
CHANGED
@@ -228,9 +228,9 @@
|
|
228
228
|
</div>
|
229
229
|
|
230
230
|
<div id="footer">
|
231
|
-
Generated on
|
231
|
+
Generated on Mon Dec 16 10:41:42 2024 by
|
232
232
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
233
|
-
0.9.37 (ruby-3.
|
233
|
+
0.9.37 (ruby-3.3.6).
|
234
234
|
</div>
|
235
235
|
|
236
236
|
</div>
|
data/doc/_index.html
CHANGED
@@ -135,9 +135,9 @@
|
|
135
135
|
</div>
|
136
136
|
|
137
137
|
<div id="footer">
|
138
|
-
Generated on
|
138
|
+
Generated on Mon Dec 16 10:41:42 2024 by
|
139
139
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
140
|
-
0.9.37 (ruby-3.
|
140
|
+
0.9.37 (ruby-3.3.6).
|
141
141
|
</div>
|
142
142
|
|
143
143
|
</div>
|
data/doc/file.README.html
CHANGED
@@ -384,7 +384,7 @@
|
|
384
384
|
<ul><li>
|
385
385
|
<p><strong>Info Level</strong>: Respects the skip list, excluding predefined sensitive or irrelevant variables. Global variables are ignored.</p>
|
386
386
|
</li><li>
|
387
|
-
<p><strong>Debug Level</strong>: Ignores the skip lists, capturing all variables including those typically excluded and global variables.
|
387
|
+
<p><strong>Debug Level</strong>: Ignores the skip lists, capturing all variables including those typically excluded and global variables. Global variables are only captured in debug mode, and they exclude the default Ruby global variables.</p>
|
388
388
|
</li></ul>
|
389
389
|
|
390
390
|
<p><strong>Default Behavior</strong>: By default, <code>info</code> level is used, which excludes variables in the skip list to protect sensitive information. In <code>debug</code> mode, the skip lists are ignored to provide more comprehensive data, which is useful during development but should be used cautiously to avoid exposing sensitive data. The info mode is recommended.</p>
|
@@ -486,9 +486,9 @@
|
|
486
486
|
</div></div>
|
487
487
|
|
488
488
|
<div id="footer">
|
489
|
-
Generated on
|
489
|
+
Generated on Mon Dec 16 10:41:42 2024 by
|
490
490
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
491
|
-
0.9.37 (ruby-3.
|
491
|
+
0.9.37 (ruby-3.3.6).
|
492
492
|
</div>
|
493
493
|
|
494
494
|
</div>
|
data/doc/index.html
CHANGED
@@ -384,7 +384,7 @@
|
|
384
384
|
<ul><li>
|
385
385
|
<p><strong>Info Level</strong>: Respects the skip list, excluding predefined sensitive or irrelevant variables. Global variables are ignored.</p>
|
386
386
|
</li><li>
|
387
|
-
<p><strong>Debug Level</strong>: Ignores the skip lists, capturing all variables including those typically excluded and global variables.
|
387
|
+
<p><strong>Debug Level</strong>: Ignores the skip lists, capturing all variables including those typically excluded and global variables. Global variables are only captured in debug mode, and they exclude the default Ruby global variables.</p>
|
388
388
|
</li></ul>
|
389
389
|
|
390
390
|
<p><strong>Default Behavior</strong>: By default, <code>info</code> level is used, which excludes variables in the skip list to protect sensitive information. In <code>debug</code> mode, the skip lists are ignored to provide more comprehensive data, which is useful during development but should be used cautiously to avoid exposing sensitive data. The info mode is recommended.</p>
|
@@ -486,9 +486,9 @@
|
|
486
486
|
</div></div>
|
487
487
|
|
488
488
|
<div id="footer">
|
489
|
-
Generated on
|
489
|
+
Generated on Mon Dec 16 10:41:42 2024 by
|
490
490
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
491
|
-
0.9.37 (ruby-3.
|
491
|
+
0.9.37 (ruby-3.3.6).
|
492
492
|
</div>
|
493
493
|
|
494
494
|
</div>
|
data/doc/method_list.html
CHANGED
@@ -105,7 +105,7 @@
|
|
105
105
|
|
106
106
|
<li class="even ">
|
107
107
|
<div class="item">
|
108
|
-
<span class='object_link'><a href="EnhancedErrors.html#
|
108
|
+
<span class='object_link'><a href="EnhancedErrors.html#capture_limit_exceeded%3F-class_method" title="EnhancedErrors.capture_limit_exceeded? (method)">capture_limit_exceeded?</a></span>
|
109
109
|
<small>EnhancedErrors</small>
|
110
110
|
</div>
|
111
111
|
</li>
|
@@ -113,13 +113,21 @@
|
|
113
113
|
|
114
114
|
<li class="odd ">
|
115
115
|
<div class="item">
|
116
|
-
<span class='object_link'><a href="EnhancedErrors.html#capture_rescue
|
116
|
+
<span class='object_link'><a href="EnhancedErrors.html#capture_rescue-class_method" title="EnhancedErrors.capture_rescue (method)">capture_rescue</a></span>
|
117
117
|
<small>EnhancedErrors</small>
|
118
118
|
</div>
|
119
119
|
</li>
|
120
120
|
|
121
121
|
|
122
122
|
<li class="even ">
|
123
|
+
<div class="item">
|
124
|
+
<span class='object_link'><a href="EnhancedErrors.html#capture_rescue=-class_method" title="EnhancedErrors.capture_rescue= (method)">capture_rescue=</a></span>
|
125
|
+
<small>EnhancedErrors</small>
|
126
|
+
</div>
|
127
|
+
</li>
|
128
|
+
|
129
|
+
|
130
|
+
<li class="odd ">
|
123
131
|
<div class="item">
|
124
132
|
<span class='object_link'><a href="Exception.html#captured_variables-instance_method" title="Exception#captured_variables (method)">#captured_variables</a></span>
|
125
133
|
<small>Exception</small>
|
@@ -127,7 +135,7 @@
|
|
127
135
|
</li>
|
128
136
|
|
129
137
|
|
130
|
-
<li class="
|
138
|
+
<li class="even ">
|
131
139
|
<div class="item">
|
132
140
|
<span class='object_link'><a href="EnhancedErrors.html#class_to_string-class_method" title="EnhancedErrors.class_to_string (method)">class_to_string</a></span>
|
133
141
|
<small>EnhancedErrors</small>
|
@@ -135,7 +143,7 @@
|
|
135
143
|
</li>
|
136
144
|
|
137
145
|
|
138
|
-
<li class="
|
146
|
+
<li class="odd ">
|
139
147
|
<div class="item">
|
140
148
|
<span class='object_link'><a href="Enhanced/Colors.html#code-class_method" title="Enhanced::Colors.code (method)">code</a></span>
|
141
149
|
<small>Enhanced::Colors</small>
|
@@ -143,7 +151,7 @@
|
|
143
151
|
</li>
|
144
152
|
|
145
153
|
|
146
|
-
<li class="
|
154
|
+
<li class="even ">
|
147
155
|
<div class="item">
|
148
156
|
<span class='object_link'><a href="Enhanced/Colors.html#color-class_method" title="Enhanced::Colors.color (method)">color</a></span>
|
149
157
|
<small>Enhanced::Colors</small>
|
@@ -151,7 +159,7 @@
|
|
151
159
|
</li>
|
152
160
|
|
153
161
|
|
154
|
-
<li class="
|
162
|
+
<li class="odd ">
|
155
163
|
<div class="item">
|
156
164
|
<span class='object_link'><a href="EnhancedErrors.html#config_block-class_method" title="EnhancedErrors.config_block (method)">config_block</a></span>
|
157
165
|
<small>EnhancedErrors</small>
|
@@ -159,7 +167,7 @@
|
|
159
167
|
</li>
|
160
168
|
|
161
169
|
|
162
|
-
<li class="
|
170
|
+
<li class="even ">
|
163
171
|
<div class="item">
|
164
172
|
<span class='object_link'><a href="EnhancedErrors.html#convert_binding_to_binding_info-class_method" title="EnhancedErrors.convert_binding_to_binding_info (method)">convert_binding_to_binding_info</a></span>
|
165
173
|
<small>EnhancedErrors</small>
|
@@ -167,6 +175,14 @@
|
|
167
175
|
</li>
|
168
176
|
|
169
177
|
|
178
|
+
<li class="odd ">
|
179
|
+
<div class="item">
|
180
|
+
<span class='object_link'><a href="EnhancedErrors.html#disable_capturing!-class_method" title="EnhancedErrors.disable_capturing! (method)">disable_capturing!</a></span>
|
181
|
+
<small>EnhancedErrors</small>
|
182
|
+
</div>
|
183
|
+
</li>
|
184
|
+
|
185
|
+
|
170
186
|
<li class="even ">
|
171
187
|
<div class="item">
|
172
188
|
<span class='object_link'><a href="EnhancedErrors.html#eligible_for_capture-class_method" title="EnhancedErrors.eligible_for_capture (method)">eligible_for_capture</a></span>
|
@@ -200,6 +216,14 @@
|
|
200
216
|
|
201
217
|
|
202
218
|
<li class="even ">
|
219
|
+
<div class="item">
|
220
|
+
<span class='object_link'><a href="EnhancedErrors.html#enforce_capture_limit!-class_method" title="EnhancedErrors.enforce_capture_limit! (method)">enforce_capture_limit!</a></span>
|
221
|
+
<small>EnhancedErrors</small>
|
222
|
+
</div>
|
223
|
+
</li>
|
224
|
+
|
225
|
+
|
226
|
+
<li class="odd ">
|
203
227
|
<div class="item">
|
204
228
|
<span class='object_link'><a href="EnhancedErrors.html#enhance_exceptions!-class_method" title="EnhancedErrors.enhance_exceptions! (method)">enhance_exceptions!</a></span>
|
205
229
|
<small>EnhancedErrors</small>
|
@@ -207,6 +231,14 @@
|
|
207
231
|
</li>
|
208
232
|
|
209
233
|
|
234
|
+
<li class="even ">
|
235
|
+
<div class="item">
|
236
|
+
<span class='object_link'><a href="EnhancedErrors.html#exception_trace-class_method" title="EnhancedErrors.exception_trace (method)">exception_trace</a></span>
|
237
|
+
<small>EnhancedErrors</small>
|
238
|
+
</div>
|
239
|
+
</li>
|
240
|
+
|
241
|
+
|
210
242
|
<li class="odd ">
|
211
243
|
<div class="item">
|
212
244
|
<span class='object_link'><a href="EnhancedErrors.html#format-class_method" title="EnhancedErrors.format (method)">format</a></span>
|
@@ -384,14 +416,6 @@
|
|
384
416
|
|
385
417
|
|
386
418
|
<li class="odd ">
|
387
|
-
<div class="item">
|
388
|
-
<span class='object_link'><a href="EnhancedErrors.html#safely_prepend_rspec_custom_failure_message-class_method" title="EnhancedErrors.safely_prepend_rspec_custom_failure_message (method)">safely_prepend_rspec_custom_failure_message</a></span>
|
389
|
-
<small>EnhancedErrors</small>
|
390
|
-
</div>
|
391
|
-
</li>
|
392
|
-
|
393
|
-
|
394
|
-
<li class="even ">
|
395
419
|
<div class="item">
|
396
420
|
<span class='object_link'><a href="EnhancedErrors.html#skip_list-class_method" title="EnhancedErrors.skip_list (method)">skip_list</a></span>
|
397
421
|
<small>EnhancedErrors</small>
|
@@ -399,17 +423,9 @@
|
|
399
423
|
</li>
|
400
424
|
|
401
425
|
|
402
|
-
<li class="odd ">
|
403
|
-
<div class="item">
|
404
|
-
<span class='object_link'><a href="EnhancedErrors.html#start_minitest_binding_capture-class_method" title="EnhancedErrors.start_minitest_binding_capture (method)">start_minitest_binding_capture</a></span>
|
405
|
-
<small>EnhancedErrors</small>
|
406
|
-
</div>
|
407
|
-
</li>
|
408
|
-
|
409
|
-
|
410
426
|
<li class="even ">
|
411
427
|
<div class="item">
|
412
|
-
<span class='object_link'><a href="EnhancedErrors.html#
|
428
|
+
<span class='object_link'><a href="EnhancedErrors.html#start_minitest_binding_capture-class_method" title="EnhancedErrors.start_minitest_binding_capture (method)">start_minitest_binding_capture</a></span>
|
413
429
|
<small>EnhancedErrors</small>
|
414
430
|
</div>
|
415
431
|
</li>
|
@@ -417,7 +433,7 @@
|
|
417
433
|
|
418
434
|
<li class="odd ">
|
419
435
|
<div class="item">
|
420
|
-
<span class='object_link'><a href="EnhancedErrors.html#
|
436
|
+
<span class='object_link'><a href="EnhancedErrors.html#start_rspec_binding_capture-class_method" title="EnhancedErrors.start_rspec_binding_capture (method)">start_rspec_binding_capture</a></span>
|
421
437
|
<small>EnhancedErrors</small>
|
422
438
|
</div>
|
423
439
|
</li>
|
@@ -425,7 +441,7 @@
|
|
425
441
|
|
426
442
|
<li class="even ">
|
427
443
|
<div class="item">
|
428
|
-
<span class='object_link'><a href="EnhancedErrors.html#
|
444
|
+
<span class='object_link'><a href="EnhancedErrors.html#stop_minitest_binding_capture-class_method" title="EnhancedErrors.stop_minitest_binding_capture (method)">stop_minitest_binding_capture</a></span>
|
429
445
|
<small>EnhancedErrors</small>
|
430
446
|
</div>
|
431
447
|
</li>
|
@@ -433,7 +449,7 @@
|
|
433
449
|
|
434
450
|
<li class="odd ">
|
435
451
|
<div class="item">
|
436
|
-
<span class='object_link'><a href="EnhancedErrors.html#
|
452
|
+
<span class='object_link'><a href="EnhancedErrors.html#stop_rspec_binding_capture-class_method" title="EnhancedErrors.stop_rspec_binding_capture (method)">stop_rspec_binding_capture</a></span>
|
437
453
|
<small>EnhancedErrors</small>
|
438
454
|
</div>
|
439
455
|
</li>
|
@@ -122,9 +122,9 @@
|
|
122
122
|
</div>
|
123
123
|
|
124
124
|
<div id="footer">
|
125
|
-
Generated on
|
125
|
+
Generated on Mon Dec 16 10:41:42 2024 by
|
126
126
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
127
|
-
0.9.37 (ruby-3.
|
127
|
+
0.9.37 (ruby-3.3.6).
|
128
128
|
</div>
|
129
129
|
|
130
130
|
</div>
|
data/enhanced_errors.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "enhanced_errors"
|
3
|
-
spec.version = "2.1.
|
3
|
+
spec.version = "2.1.2"
|
4
4
|
spec.authors = ["Eric Beland"]
|
5
5
|
|
6
6
|
spec.summary = "Automatically enhance your errors with messages containing variable values from the moment they were raised."
|
data/lib/enhanced_errors.rb
CHANGED
@@ -21,65 +21,64 @@ class EnhancedErrors
|
|
21
21
|
@monitor ||= Monitor.new
|
22
22
|
end
|
23
23
|
|
24
|
-
attr_accessor :enabled, :config_block, :on_capture_hook, :eligible_for_capture, :
|
24
|
+
attr_accessor :enabled, :config_block, :on_capture_hook, :eligible_for_capture, :exception_trace, :override_messages
|
25
25
|
|
26
26
|
GEMS_REGEX = %r{[\/\\]gems[\/\\]}
|
27
|
-
RSPEC_EXAMPLE_REGEXP = /RSpec::ExampleGroups::[A-Z0-9]+.*/
|
28
27
|
DEFAULT_MAX_LENGTH = 2000
|
29
28
|
MAX_BINDING_INFOS = 3
|
30
29
|
|
31
30
|
RSPEC_SKIP_LIST = [
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
31
|
+
:@__inspect_output,
|
32
|
+
:@__memoized,
|
33
|
+
:@assertion_delegator,
|
34
|
+
:@assertion_instance,
|
35
|
+
:@assertions,
|
36
|
+
:@connection_subscriber,
|
37
|
+
:@example,
|
38
|
+
:@fixture_cache,
|
39
|
+
:@fixture_cache_key,
|
40
|
+
:@fixture_connection_pools,
|
41
|
+
:@fixture_connections,
|
42
|
+
:@integration_session,
|
43
|
+
:@legacy_saved_pool_configs,
|
44
|
+
:@loaded_fixtures,
|
45
|
+
:@matcher_definitions,
|
46
|
+
:@saved_pool_configs
|
47
|
+
].freeze
|
49
48
|
|
50
49
|
RAILS_SKIP_LIST = [
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
50
|
+
:@new_record,
|
51
|
+
:@attributes,
|
52
|
+
:@association_cache,
|
53
|
+
:@readonly,
|
54
|
+
:@previously_new_record,
|
55
|
+
:@_routes,
|
56
|
+
:@routes,
|
57
|
+
:@app,
|
58
|
+
:@arel_table,
|
59
|
+
:@assertion_instance,
|
60
|
+
:@association_cache,
|
61
|
+
:@attributes,
|
62
|
+
:@destroyed,
|
63
|
+
:@destroyed_by_association,
|
64
|
+
:@find_by_statement_cache,
|
65
|
+
:@generated_relation_method,
|
66
|
+
:@integration_session,
|
67
|
+
:@marked_for_destruction,
|
68
|
+
:@mutations_before_last_save,
|
69
|
+
:@mutations_from_database,
|
70
|
+
:@new_record,
|
71
|
+
:@predicate_builder,
|
72
|
+
:@previously_new_record,
|
73
|
+
:@primary_key,
|
74
|
+
:@readonly,
|
75
|
+
:@relation_delegate_cache,
|
76
|
+
:@response,
|
77
|
+
:@response_klass,
|
78
|
+
:@routes,
|
79
|
+
:@strict_loading,
|
80
|
+
:@strict_loading_mode
|
81
|
+
].freeze
|
83
82
|
|
84
83
|
MINITEST_SKIP_LIST = [:@NAME, :@failures, :@time].freeze
|
85
84
|
|
@@ -96,12 +95,11 @@ class EnhancedErrors
|
|
96
95
|
@output_format = nil
|
97
96
|
@eligible_for_capture = nil
|
98
97
|
@original_global_variables = nil
|
99
|
-
@
|
98
|
+
@exception_trace = nil
|
100
99
|
@override_messages = nil
|
101
|
-
@rspec_failure_message_loaded = nil
|
102
100
|
|
103
101
|
# Default values
|
104
|
-
@max_capture_events = -1
|
102
|
+
@max_capture_events = -1 # -1 means no limit
|
105
103
|
@capture_events_count = 0
|
106
104
|
|
107
105
|
# Thread-safe getters and setters
|
@@ -118,11 +116,11 @@ class EnhancedErrors
|
|
118
116
|
end
|
119
117
|
|
120
118
|
def capture_rescue
|
121
|
-
mutex.synchronize {
|
119
|
+
mutex.synchronize { @capture_rescue }
|
122
120
|
end
|
123
121
|
|
124
122
|
def capture_events_count
|
125
|
-
mutex.synchronize { @capture_events_count }
|
123
|
+
mutex.synchronize { @capture_events_count || 0 }
|
126
124
|
end
|
127
125
|
|
128
126
|
def capture_events_count=(val)
|
@@ -130,7 +128,7 @@ class EnhancedErrors
|
|
130
128
|
end
|
131
129
|
|
132
130
|
def max_capture_events
|
133
|
-
mutex.synchronize { @max_capture_events }
|
131
|
+
mutex.synchronize { @max_capture_events || -1 }
|
134
132
|
end
|
135
133
|
|
136
134
|
def max_capture_events=(value)
|
@@ -141,7 +139,7 @@ class EnhancedErrors
|
|
141
139
|
if @enabled
|
142
140
|
puts "EnhancedErrors: max_capture_events set to 0, disabling capturing."
|
143
141
|
@enabled = false
|
144
|
-
@
|
142
|
+
@exception_trace&.disable
|
145
143
|
@rspec_tracepoint&.disable
|
146
144
|
@minitest_trace&.disable
|
147
145
|
end
|
@@ -149,25 +147,36 @@ class EnhancedErrors
|
|
149
147
|
end
|
150
148
|
end
|
151
149
|
|
150
|
+
def enforce_capture_limit!
|
151
|
+
disable_capturing! if capture_limit_exceeded?
|
152
|
+
end
|
153
|
+
|
154
|
+
def capture_limit_exceeded?
|
155
|
+
mutex.synchronize do
|
156
|
+
max_capture_events > 0 && capture_events_count >= max_capture_events
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def disable_capturing!
|
161
|
+
mutex.synchronize do
|
162
|
+
@enabled = false
|
163
|
+
@rspec_tracepoint&.disable
|
164
|
+
@minitest_trace&.disable
|
165
|
+
@exception_trace&.disable
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
152
169
|
def increment_capture_events_count
|
153
170
|
mutex.synchronize do
|
154
171
|
@capture_events_count ||= 0
|
155
172
|
@max_capture_events ||= -1
|
156
173
|
@capture_events_count += 1
|
157
|
-
# Check if we've hit the limit
|
158
|
-
if @max_capture_events > 0 && @capture_events_count >= @max_capture_events
|
159
|
-
# puts "EnhancedErrors: max_capture_events limit (#{@max_capture_events}) reached, disabling capturing."
|
160
|
-
@enabled = false
|
161
|
-
end
|
162
174
|
end
|
163
175
|
end
|
164
176
|
|
165
177
|
def reset_capture_events_count
|
166
178
|
mutex.synchronize do
|
167
179
|
@capture_events_count = 0
|
168
|
-
@enabled = true
|
169
|
-
@rspec_tracepoint.enable if @rspec_tracepoint
|
170
|
-
@trace.enable if @trace
|
171
180
|
end
|
172
181
|
end
|
173
182
|
|
@@ -228,8 +237,8 @@ class EnhancedErrors
|
|
228
237
|
|
229
238
|
def enhance_exceptions!(enabled: true, debug: false, capture_events: nil, override_messages: false, **options, &block)
|
230
239
|
mutex.synchronize do
|
231
|
-
@
|
232
|
-
@
|
240
|
+
@exception_trace&.disable
|
241
|
+
@exception_trace = nil
|
233
242
|
|
234
243
|
@output_format = nil
|
235
244
|
@eligible_for_capture = nil
|
@@ -237,7 +246,9 @@ class EnhancedErrors
|
|
237
246
|
@override_messages = override_messages
|
238
247
|
|
239
248
|
# Ensure these are not nil
|
240
|
-
|
249
|
+
if @max_capture_events.nil?
|
250
|
+
@max_capture_events = -1
|
251
|
+
end
|
241
252
|
@capture_events_count = 0
|
242
253
|
|
243
254
|
@rspec_failure_message_loaded = true
|
@@ -273,13 +284,13 @@ class EnhancedErrors
|
|
273
284
|
end
|
274
285
|
|
275
286
|
events = @capture_events ? @capture_events.to_a : default_capture_events
|
276
|
-
@
|
287
|
+
@exception_trace = TracePoint.new(*events) do |tp|
|
277
288
|
handle_tracepoint_event(tp)
|
278
289
|
end
|
279
290
|
|
280
291
|
# Only enable trace if still enabled and not limited
|
281
292
|
if @enabled && (@max_capture_events == -1 || @capture_events_count < @max_capture_events)
|
282
|
-
@
|
293
|
+
@exception_trace.enable
|
283
294
|
end
|
284
295
|
end
|
285
296
|
end
|
@@ -295,23 +306,12 @@ class EnhancedErrors
|
|
295
306
|
end
|
296
307
|
end
|
297
308
|
|
298
|
-
def safely_prepend_rspec_custom_failure_message
|
299
|
-
mutex.synchronize do
|
300
|
-
return if @rspec_failure_message_loaded
|
301
|
-
if defined?(RSpec::Core::Example) && !RSpec::Core::Example < Enhanced::Integrations::RSpecErrorFailureMessage
|
302
|
-
RSpec::Core::Example.prepend(Enhanced::Integrations::RSpecErrorFailureMessage)
|
303
|
-
@rspec_failure_message_loaded = true
|
304
|
-
end
|
305
|
-
end
|
306
|
-
rescue => e
|
307
|
-
puts "Failed to prepend RSpec custom failure message: #{e.message}"
|
308
|
-
end
|
309
|
-
|
310
309
|
def is_a_minitest?(klass)
|
311
310
|
klass.ancestors.include?(Minitest::Test) && klass.name != 'Minitest::Test'
|
312
311
|
end
|
313
312
|
|
314
313
|
def start_minitest_binding_capture
|
314
|
+
return if capture_limit_exceeded?
|
315
315
|
mutex.synchronize do
|
316
316
|
@minitest_trace = TracePoint.new(:return) do |tp|
|
317
317
|
next unless tp.method_id.to_s.start_with?('test_') && is_a_minitest?(tp.defined_class)
|
@@ -322,6 +322,7 @@ class EnhancedErrors
|
|
322
322
|
end
|
323
323
|
|
324
324
|
def stop_minitest_binding_capture
|
325
|
+
disable_capturing! if capture_limit_exceeded?
|
325
326
|
mutex.synchronize do
|
326
327
|
@minitest_trace&.disable
|
327
328
|
@minitest_trace = nil
|
@@ -332,22 +333,22 @@ class EnhancedErrors
|
|
332
333
|
def class_to_string(klass)
|
333
334
|
return '' if klass.nil?
|
334
335
|
if klass.singleton_class?
|
335
|
-
klass.to_s.match(/#<Class:(.*?)>/)[1]
|
336
|
+
(match = klass.to_s.match(/#<Class:(.*?)>/)) ? match[1] : klass.to_s
|
336
337
|
else
|
337
338
|
klass.to_s
|
338
339
|
end
|
339
340
|
end
|
340
341
|
|
341
342
|
def is_rspec_example?(tracepoint)
|
342
|
-
tracepoint.method_id.nil?
|
343
|
+
tracepoint.method_id.nil? && !(tracepoint.path.include?('rspec')) && tracepoint.path.end_with?('_spec.rb')
|
343
344
|
end
|
344
345
|
|
345
346
|
def start_rspec_binding_capture
|
347
|
+
return if capture_limit_exceeded?
|
346
348
|
mutex.synchronize do
|
347
349
|
@rspec_example_binding = nil
|
348
350
|
@capture_next_binding = false
|
349
351
|
@rspec_tracepoint&.disable
|
350
|
-
@enabled = true if @enabled.nil?
|
351
352
|
|
352
353
|
@rspec_tracepoint = TracePoint.new(:raise, :b_return) do |tp|
|
353
354
|
# puts "name #{tp.raised_exception.class.name rescue ''} method:#{tp.method_id} tp.binding:#{tp.binding.local_variables rescue ''}"
|
@@ -381,6 +382,7 @@ class EnhancedErrors
|
|
381
382
|
end
|
382
383
|
|
383
384
|
def stop_rspec_binding_capture
|
385
|
+
disable_capturing! if capture_limit_exceeded?
|
384
386
|
mutex.synchronize do
|
385
387
|
@rspec_tracepoint&.disable
|
386
388
|
@rspec_tracepoint = nil
|
@@ -606,6 +608,7 @@ class EnhancedErrors
|
|
606
608
|
|
607
609
|
def handle_tracepoint_event(tp)
|
608
610
|
# Check enabled outside the synchronized block for speed, but still safe due to re-check inside.
|
611
|
+
enforce_capture_limit!
|
609
612
|
return unless mutex.synchronize { @enabled }
|
610
613
|
return if Thread.current[:enhanced_errors_processing] || Thread.current[:on_capture] || ignored_exception?(tp.raised_exception)
|
611
614
|
|
@@ -751,7 +754,7 @@ class EnhancedErrors
|
|
751
754
|
end
|
752
755
|
|
753
756
|
def valid_capture_events?(capture_events)
|
754
|
-
capture_events.is_a?(Array) && [:raise, :rescue]
|
757
|
+
capture_events.is_a?(Array) && capture_events.all? { |ev| [:raise, :rescue].include?(ev) }
|
755
758
|
end
|
756
759
|
|
757
760
|
def extract_arguments(tp, method_name)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enhanced_errors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Beland
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
- !ruby/object:Gem::Version
|
137
137
|
version: '0'
|
138
138
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
139
|
+
rubygems_version: 3.5.22
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: Automatically enhance your errors with messages containing variable values
|