enhanced_errors 2.2.0 → 3.0.1

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.
@@ -387,7 +387,7 @@
387
387
  </div>
388
388
 
389
389
  <div id="footer">
390
- Generated on Tue Dec 17 14:09:26 2024 by
390
+ Generated on Tue Dec 17 15:42:48 2024 by
391
391
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
392
392
  0.9.37 (ruby-3.3.6).
393
393
  </div>
data/doc/Exception.html CHANGED
@@ -111,7 +111,7 @@
111
111
  </div>
112
112
 
113
113
  <div id="footer">
114
- Generated on Tue Dec 17 14:09:26 2024 by
114
+ Generated on Tue Dec 17 15:42:48 2024 by
115
115
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
116
116
  0.9.37 (ruby-3.3.6).
117
117
  </div>
@@ -245,7 +245,7 @@
245
245
  </div>
246
246
 
247
247
  <div id="footer">
248
- Generated on Tue Dec 17 14:09:26 2024 by
248
+ Generated on Tue Dec 17 15:42:48 2024 by
249
249
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
250
250
  0.9.37 (ruby-3.3.6).
251
251
  </div>
data/doc/Minitest.html CHANGED
@@ -228,7 +228,7 @@
228
228
  </div>
229
229
 
230
230
  <div id="footer">
231
- Generated on Tue Dec 17 14:09:26 2024 by
231
+ Generated on Tue Dec 17 15:42:48 2024 by
232
232
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
233
233
  0.9.37 (ruby-3.3.6).
234
234
  </div>
data/doc/_index.html CHANGED
@@ -150,7 +150,7 @@
150
150
  </div>
151
151
 
152
152
  <div id="footer">
153
- Generated on Tue Dec 17 14:09:26 2024 by
153
+ Generated on Tue Dec 17 15:42:48 2024 by
154
154
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
155
155
  0.9.37 (ruby-3.3.6).
156
156
  </div>
data/doc/file.README.html CHANGED
@@ -243,7 +243,7 @@
243
243
  <p>You can pass configuration options to <code>enhance_exceptions!</code>:</p>
244
244
 
245
245
  <pre class="code ruby"><code class="ruby">
246
- <span class='const'><span class='object_link'><a href="EnhancedErrors.html" title="EnhancedErrors (class)">EnhancedErrors</a></span></span><span class='period'>.</span><span class='id identifier rubyid_enhance_exceptions!'><span class='object_link'><a href="EnhancedErrors.html#enhance_exceptions!-class_method" title="EnhancedErrors.enhance_exceptions! (method)">enhance_exceptions!</a></span></span><span class='lparen'>(</span><span class='label'>enabled:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>max_length:</span> <span class='int'>2000</span><span class='rparen'>)</span> <span class='kw'>do</span>
246
+ <span class='const'><span class='object_link'><a href="EnhancedErrors.html" title="EnhancedErrors (class)">EnhancedErrors</a></span></span><span class='period'>.</span><span class='id identifier rubyid_enhance_exceptions!'><span class='object_link'><a href="EnhancedErrors.html#enhance_exceptions!-class_method" title="EnhancedErrors.enhance_exceptions! (method)">enhance_exceptions!</a></span></span><span class='lparen'>(</span><span class='label'>enabled:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>max_capture_length:</span> <span class='int'>2000</span><span class='rparen'>)</span> <span class='kw'>do</span>
247
247
  <span class='comment'># Additional configuration here
248
248
  </span> <span class='id identifier rubyid_add_to_skip_list'>add_to_skip_list</span> <span class='symbol'>:@instance_variable_to_skip</span><span class='comma'>,</span> <span class='symbol'>:local_to_skip</span>
249
249
  <span class='kw'>end</span>
@@ -253,7 +253,7 @@
253
253
  </li><li>
254
254
  <p><code>enabled</code>: Enables or disables the enhancement (default: <code>true</code>).</p>
255
255
  </li><li>
256
- <p><code>max_length</code>: Sets the maximum length of the captured_variables string (default: <code>2500</code>).</p>
256
+ <p><code>max_capture_length</code>: Sets the maximum length of the captured_variables string (default: <code>2500</code>).</p>
257
257
  </li></ul>
258
258
 
259
259
  <h3 id="label-Environment-Based+Defaults">Environment-Based Defaults</h3>
@@ -486,7 +486,7 @@
486
486
  </div></div>
487
487
 
488
488
  <div id="footer">
489
- Generated on Tue Dec 17 14:09:26 2024 by
489
+ Generated on Tue Dec 17 15:42:48 2024 by
490
490
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
491
491
  0.9.37 (ruby-3.3.6).
492
492
  </div>
data/doc/index.html CHANGED
@@ -243,7 +243,7 @@
243
243
  <p>You can pass configuration options to <code>enhance_exceptions!</code>:</p>
244
244
 
245
245
  <pre class="code ruby"><code class="ruby">
246
- <span class='const'><span class='object_link'><a href="EnhancedErrors.html" title="EnhancedErrors (class)">EnhancedErrors</a></span></span><span class='period'>.</span><span class='id identifier rubyid_enhance_exceptions!'><span class='object_link'><a href="EnhancedErrors.html#enhance_exceptions!-class_method" title="EnhancedErrors.enhance_exceptions! (method)">enhance_exceptions!</a></span></span><span class='lparen'>(</span><span class='label'>enabled:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>max_length:</span> <span class='int'>2000</span><span class='rparen'>)</span> <span class='kw'>do</span>
246
+ <span class='const'><span class='object_link'><a href="EnhancedErrors.html" title="EnhancedErrors (class)">EnhancedErrors</a></span></span><span class='period'>.</span><span class='id identifier rubyid_enhance_exceptions!'><span class='object_link'><a href="EnhancedErrors.html#enhance_exceptions!-class_method" title="EnhancedErrors.enhance_exceptions! (method)">enhance_exceptions!</a></span></span><span class='lparen'>(</span><span class='label'>enabled:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>max_capture_length:</span> <span class='int'>2000</span><span class='rparen'>)</span> <span class='kw'>do</span>
247
247
  <span class='comment'># Additional configuration here
248
248
  </span> <span class='id identifier rubyid_add_to_skip_list'>add_to_skip_list</span> <span class='symbol'>:@instance_variable_to_skip</span><span class='comma'>,</span> <span class='symbol'>:local_to_skip</span>
249
249
  <span class='kw'>end</span>
@@ -253,7 +253,7 @@
253
253
  </li><li>
254
254
  <p><code>enabled</code>: Enables or disables the enhancement (default: <code>true</code>).</p>
255
255
  </li><li>
256
- <p><code>max_length</code>: Sets the maximum length of the captured_variables string (default: <code>2500</code>).</p>
256
+ <p><code>max_capture_length</code>: Sets the maximum length of the captured_variables string (default: <code>2500</code>).</p>
257
257
  </li></ul>
258
258
 
259
259
  <h3 id="label-Environment-Based+Defaults">Environment-Based Defaults</h3>
@@ -486,7 +486,7 @@
486
486
  </div></div>
487
487
 
488
488
  <div id="footer">
489
- Generated on Tue Dec 17 14:09:26 2024 by
489
+ Generated on Tue Dec 17 15:42:48 2024 by
490
490
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
491
491
  0.9.37 (ruby-3.3.6).
492
492
  </div>
data/doc/method_list.html CHANGED
@@ -249,7 +249,7 @@
249
249
 
250
250
  <li class="even ">
251
251
  <div class="item">
252
- <span class='object_link'><a href="EnhancedErrors.html#enforce_capture_limit-class_method" title="EnhancedErrors.enforce_capture_limit (method)">enforce_capture_limit</a></span>
252
+ <span class='object_link'><a href="EnhancedErrors.html#enhance_exceptions!-class_method" title="EnhancedErrors.enhance_exceptions! (method)">enhance_exceptions!</a></span>
253
253
  <small>EnhancedErrors</small>
254
254
  </div>
255
255
  </li>
@@ -257,7 +257,7 @@
257
257
 
258
258
  <li class="odd ">
259
259
  <div class="item">
260
- <span class='object_link'><a href="EnhancedErrors.html#enhance_exceptions!-class_method" title="EnhancedErrors.enhance_exceptions! (method)">enhance_exceptions!</a></span>
260
+ <span class='object_link'><a href="EnhancedErrors.html#exception_trace-class_method" title="EnhancedErrors.exception_trace (method)">exception_trace</a></span>
261
261
  <small>EnhancedErrors</small>
262
262
  </div>
263
263
  </li>
@@ -265,7 +265,7 @@
265
265
 
266
266
  <li class="even ">
267
267
  <div class="item">
268
- <span class='object_link'><a href="EnhancedErrors.html#exception_trace-class_method" title="EnhancedErrors.exception_trace (method)">exception_trace</a></span>
268
+ <span class='object_link'><a href="EnhancedErrors.html#format-class_method" title="EnhancedErrors.format (method)">format</a></span>
269
269
  <small>EnhancedErrors</small>
270
270
  </div>
271
271
  </li>
@@ -273,7 +273,7 @@
273
273
 
274
274
  <li class="odd ">
275
275
  <div class="item">
276
- <span class='object_link'><a href="EnhancedErrors.html#format-class_method" title="EnhancedErrors.format (method)">format</a></span>
276
+ <span class='object_link'><a href="EnhancedErrors.html#get_default_format_for_environment-class_method" title="EnhancedErrors.get_default_format_for_environment (method)">get_default_format_for_environment</a></span>
277
277
  <small>EnhancedErrors</small>
278
278
  </div>
279
279
  </li>
@@ -281,7 +281,7 @@
281
281
 
282
282
  <li class="even ">
283
283
  <div class="item">
284
- <span class='object_link'><a href="EnhancedErrors.html#get_default_format_for_environment-class_method" title="EnhancedErrors.get_default_format_for_environment (method)">get_default_format_for_environment</a></span>
284
+ <span class='object_link'><a href="EnhancedErrors.html#increment_capture_events_count-class_method" title="EnhancedErrors.increment_capture_events_count (method)">increment_capture_events_count</a></span>
285
285
  <small>EnhancedErrors</small>
286
286
  </div>
287
287
  </li>
@@ -289,23 +289,23 @@
289
289
 
290
290
  <li class="odd ">
291
291
  <div class="item">
292
- <span class='object_link'><a href="EnhancedErrors.html#increment_capture_events_count-class_method" title="EnhancedErrors.increment_capture_events_count (method)">increment_capture_events_count</a></span>
293
- <small>EnhancedErrors</small>
292
+ <span class='object_link'><a href="Context.html#initialize-instance_method" title="Context#initialize (method)">#initialize</a></span>
293
+ <small>Context</small>
294
294
  </div>
295
295
  </li>
296
296
 
297
297
 
298
298
  <li class="even ">
299
299
  <div class="item">
300
- <span class='object_link'><a href="Context.html#initialize-instance_method" title="Context#initialize (method)">#initialize</a></span>
301
- <small>Context</small>
300
+ <span class='object_link'><a href="EnhancedErrors.html#is_a_minitest%3F-class_method" title="EnhancedErrors.is_a_minitest? (method)">is_a_minitest?</a></span>
301
+ <small>EnhancedErrors</small>
302
302
  </div>
303
303
  </li>
304
304
 
305
305
 
306
306
  <li class="odd ">
307
307
  <div class="item">
308
- <span class='object_link'><a href="EnhancedErrors.html#is_a_minitest%3F-class_method" title="EnhancedErrors.is_a_minitest? (method)">is_a_minitest?</a></span>
308
+ <span class='object_link'><a href="EnhancedErrors.html#is_rspec_example%3F-class_method" title="EnhancedErrors.is_rspec_example? (method)">is_rspec_example?</a></span>
309
309
  <small>EnhancedErrors</small>
310
310
  </div>
311
311
  </li>
@@ -313,7 +313,7 @@
313
313
 
314
314
  <li class="even ">
315
315
  <div class="item">
316
- <span class='object_link'><a href="EnhancedErrors.html#is_rspec_example%3F-class_method" title="EnhancedErrors.is_rspec_example? (method)">is_rspec_example?</a></span>
316
+ <span class='object_link'><a href="EnhancedErrors.html#max_capture_events-class_method" title="EnhancedErrors.max_capture_events (method)">max_capture_events</a></span>
317
317
  <small>EnhancedErrors</small>
318
318
  </div>
319
319
  </li>
@@ -321,7 +321,7 @@
321
321
 
322
322
  <li class="odd ">
323
323
  <div class="item">
324
- <span class='object_link'><a href="EnhancedErrors.html#max_capture_events-class_method" title="EnhancedErrors.max_capture_events (method)">max_capture_events</a></span>
324
+ <span class='object_link'><a href="EnhancedErrors.html#max_capture_events=-class_method" title="EnhancedErrors.max_capture_events= (method)">max_capture_events=</a></span>
325
325
  <small>EnhancedErrors</small>
326
326
  </div>
327
327
  </li>
@@ -329,7 +329,7 @@
329
329
 
330
330
  <li class="even ">
331
331
  <div class="item">
332
- <span class='object_link'><a href="EnhancedErrors.html#max_capture_events=-class_method" title="EnhancedErrors.max_capture_events= (method)">max_capture_events=</a></span>
332
+ <span class='object_link'><a href="EnhancedErrors.html#max_capture_length-class_method" title="EnhancedErrors.max_capture_length (method)">max_capture_length</a></span>
333
333
  <small>EnhancedErrors</small>
334
334
  </div>
335
335
  </li>
@@ -337,7 +337,7 @@
337
337
 
338
338
  <li class="odd ">
339
339
  <div class="item">
340
- <span class='object_link'><a href="EnhancedErrors.html#max_length-class_method" title="EnhancedErrors.max_length (method)">max_length</a></span>
340
+ <span class='object_link'><a href="EnhancedErrors.html#max_capture_length=-class_method" title="EnhancedErrors.max_capture_length= (method)">max_capture_length=</a></span>
341
341
  <small>EnhancedErrors</small>
342
342
  </div>
343
343
  </li>
@@ -122,7 +122,7 @@
122
122
  </div>
123
123
 
124
124
  <div id="footer">
125
- Generated on Tue Dec 17 14:09:26 2024 by
125
+ Generated on Tue Dec 17 15:42:48 2024 by
126
126
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
127
127
  0.9.37 (ruby-3.3.6).
128
128
  </div>
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "enhanced_errors"
3
- spec.version = "2.2.0"
3
+ spec.version = "3.0.1"
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."
@@ -24,7 +24,7 @@ class EnhancedErrors
24
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
- DEFAULT_MAX_LENGTH = 2000
27
+ DEFAULT_MAX_CAPTURE_LENGTH = 2500
28
28
  MAX_BINDING_INFOS = 3
29
29
 
30
30
  RSPEC_SKIP_LIST = [
@@ -87,7 +87,7 @@ class EnhancedErrors
87
87
  RSPEC_HANDLER_NAMES = ['RSpec::Expectations::PositiveExpectationHandler', 'RSpec::Expectations::NegativeExpectationHandler']
88
88
 
89
89
  @enabled = nil
90
- @max_length = nil
90
+ @max_capture_length = nil
91
91
  @capture_rescue = nil
92
92
  @skip_list = nil
93
93
  @capture_events = nil
@@ -131,18 +131,21 @@ class EnhancedErrors
131
131
  mutex.synchronize { @max_capture_events || -1 }
132
132
  end
133
133
 
134
+
135
+ def max_capture_length
136
+ mutex.synchronize { @max_capture_length || DEFAULT_MAX_CAPTURE_LENGTH }
137
+ end
138
+
139
+ def max_capture_length=(val)
140
+ mutex.synchronize { @max_capture_length = value }
141
+ end
142
+
134
143
  def max_capture_events=(value)
135
144
  mutex.synchronize do
136
145
  @max_capture_events = value
137
146
  end
138
147
  end
139
148
 
140
- def enforce_capture_limit
141
- exceeded = capture_limit_exceeded?
142
- disable_capturing! if capture_limit_exceeded?
143
- exceeded
144
- end
145
-
146
149
  def capture_limit_exceeded?
147
150
  mutex.synchronize do
148
151
  max_capture_events > 0 && capture_events_count >= max_capture_events
@@ -158,13 +161,6 @@ class EnhancedErrors
158
161
  end
159
162
  end
160
163
 
161
- def increment_capture_events_count
162
- mutex.synchronize do
163
- @capture_events_count ||= 0
164
- @max_capture_events ||= -1
165
- @capture_events_count += 1
166
- end
167
- end
168
164
 
169
165
  def reset!
170
166
  mutex.synchronize do
@@ -179,17 +175,6 @@ class EnhancedErrors
179
175
  end
180
176
  end
181
177
 
182
- def max_length(value = nil)
183
- mutex.synchronize do
184
- if value.nil?
185
- @max_length ||= DEFAULT_MAX_LENGTH
186
- else
187
- @max_length = value
188
- end
189
- @max_length
190
- end
191
- end
192
-
193
178
  def skip_list
194
179
  mutex.synchronize do
195
180
  @skip_list ||= DEFAULT_SKIP_LIST
@@ -212,16 +197,13 @@ class EnhancedErrors
212
197
 
213
198
  def override_exception_message(exception, binding_or_bindings)
214
199
  return nil unless exception && exception.respond_to?(:message)
215
- rspec_binding = !(binding_or_bindings.nil? || binding_or_bindings.empty?)
200
+ test_binding = !(binding_or_bindings.nil? || binding_or_bindings.empty?)
216
201
  exception_binding = (exception.binding_infos.length > 0)
217
202
  has_message = !(exception.respond_to?(:unaltered_message))
218
- return nil unless (rspec_binding || exception_binding) && has_message
203
+ return nil unless (test_binding || exception_binding) && has_message
219
204
 
220
205
  variable_str = EnhancedErrors.format(binding_or_bindings)
221
206
  message_str = exception.message
222
- if exception.respond_to?(:captured_variables) && !message_str.include?(exception.captured_variables)
223
- message_str += exception.captured_variables
224
- end
225
207
  exception.define_singleton_method(:unaltered_message) { message_str }
226
208
  exception.define_singleton_method(:message) do
227
209
  "#{message_str}#{variable_str}"
@@ -304,14 +286,12 @@ class EnhancedErrors
304
286
  end
305
287
 
306
288
  def start_minitest_binding_capture
307
- EnhancedExceptionContext.clear_all
308
- return if enforce_capture_limit
309
289
  @enabled = true if @enabled.nil?
290
+ return unless @enabled
310
291
  mutex.synchronize do
311
292
  @minitest_trace = TracePoint.new(:return) do |tp|
312
293
  next unless tp.method_id.to_s.start_with?('test_') && is_a_minitest?(tp.defined_class)
313
294
  @minitest_test_binding = tp.binding
314
- increment_capture_events_count
315
295
  end
316
296
  @minitest_trace.enable
317
297
  end
@@ -340,8 +320,9 @@ class EnhancedErrors
340
320
  end
341
321
 
342
322
  def start_rspec_binding_capture
343
- return if enforce_capture_limit
344
323
  @enabled = true if @enabled.nil?
324
+ return unless @enabled
325
+
345
326
  mutex.synchronize do
346
327
  @rspec_example_binding = nil
347
328
  @capture_next_binding = false
@@ -358,10 +339,8 @@ class EnhancedErrors
358
339
  next
359
340
  end
360
341
  next unless @capture_next_binding
361
-
362
342
  if @capture_next_binding == :next || @capture_next_binding == :next_matching && is_rspec_example?(tp)
363
343
  @capture_next_binding = false
364
- increment_capture_events_count
365
344
  @rspec_example_binding = tp.binding
366
345
  end
367
346
  elsif tp.event == :raise
@@ -588,7 +567,7 @@ class EnhancedErrors
588
567
  end
589
568
 
590
569
  mutex.synchronize do
591
- max_len = @max_length || DEFAULT_MAX_LENGTH
570
+ max_len = @max_capture_length || DEFAULT_MAX_CAPTURE_LENGTH
592
571
  if result.length > max_len
593
572
  result = result[0...max_len] + "... (truncated)"
594
573
  end
@@ -606,7 +585,6 @@ class EnhancedErrors
606
585
  def handle_tracepoint_event(tp)
607
586
  # Check enabled outside the synchronized block for speed, but still safe due to re-check inside.
608
587
  return unless enabled
609
- return if enforce_capture_limit
610
588
  return if Thread.current[:enhanced_errors_processing] || Thread.current[:on_capture] || ignored_exception?(tp.raised_exception)
611
589
 
612
590
  Thread.current[:enhanced_errors_processing] = true
@@ -682,7 +660,6 @@ class EnhancedErrors
682
660
 
683
661
  if binding_info
684
662
  binding_info = validate_binding_format(binding_info)
685
- increment_capture_events_count
686
663
  if binding_info && exception.binding_infos.length >= MAX_BINDING_INFOS
687
664
  exception.binding_infos.delete_at(MAX_BINDING_INFOS / 2.round)
688
665
  end
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.2.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Beland
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  requirements: []
144
- rubygems_version: 3.5.22
144
+ rubygems_version: 3.3.26
145
145
  signing_key:
146
146
  specification_version: 4
147
147
  summary: Automatically enhance your errors with messages containing variable values