enhanced_errors 2.1.3 → 3.0.0

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.
@@ -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
@@ -202,30 +187,27 @@ class EnhancedErrors
202
187
  when nil
203
188
  return nil
204
189
  when RSpec::Core::MultipleExceptionError
205
- override_exception_message(exception_obj.all_exceptions.first, binding_or_bindings)
190
+ exception_obj.all_exceptions.each do |exception|
191
+ override_exception_message(exception, binding_or_bindings)
192
+ end
206
193
  else
207
194
  override_exception_message(exception_obj, binding_or_bindings)
208
195
  end
209
-
210
196
  end
211
197
 
212
198
  def override_exception_message(exception, binding_or_bindings)
213
- return nil unless exception
214
- rspec_binding = !(binding_or_bindings.nil? || binding_or_bindings.empty?)
199
+ return nil unless exception && exception.respond_to?(:message)
200
+ test_binding = !(binding_or_bindings.nil? || binding_or_bindings.empty?)
215
201
  exception_binding = (exception.binding_infos.length > 0)
216
202
  has_message = !(exception.respond_to?(:unaltered_message))
217
- return nil unless (rspec_binding || exception_binding) && has_message
203
+ return nil unless (test_binding || exception_binding) && has_message
218
204
 
219
205
  variable_str = EnhancedErrors.format(binding_or_bindings)
220
206
  message_str = exception.message
221
- if exception.respond_to?(:captured_variables) && !message_str.include?(exception.captured_variables)
222
- message_str += exception.captured_variables
223
- end
224
207
  exception.define_singleton_method(:unaltered_message) { message_str }
225
208
  exception.define_singleton_method(:message) do
226
209
  "#{message_str}#{variable_str}"
227
210
  end
228
- exception
229
211
  end
230
212
 
231
213
  def add_to_skip_list(*vars)
@@ -304,13 +286,12 @@ class EnhancedErrors
304
286
  end
305
287
 
306
288
  def start_minitest_binding_capture
307
- return if enforce_capture_limit
289
+ EnhancedExceptionContext.clear_all
308
290
  @enabled = true if @enabled.nil?
309
291
  mutex.synchronize do
310
292
  @minitest_trace = TracePoint.new(:return) do |tp|
311
293
  next unless tp.method_id.to_s.start_with?('test_') && is_a_minitest?(tp.defined_class)
312
294
  @minitest_test_binding = tp.binding
313
- increment_capture_events_count
314
295
  end
315
296
  @minitest_trace.enable
316
297
  end
@@ -339,7 +320,6 @@ class EnhancedErrors
339
320
  end
340
321
 
341
322
  def start_rspec_binding_capture
342
- return if enforce_capture_limit
343
323
  @enabled = true if @enabled.nil?
344
324
  mutex.synchronize do
345
325
  @rspec_example_binding = nil
@@ -357,10 +337,8 @@ class EnhancedErrors
357
337
  next
358
338
  end
359
339
  next unless @capture_next_binding
360
-
361
340
  if @capture_next_binding == :next || @capture_next_binding == :next_matching && is_rspec_example?(tp)
362
341
  @capture_next_binding = false
363
- increment_capture_events_count
364
342
  @rspec_example_binding = tp.binding
365
343
  end
366
344
  elsif tp.event == :raise
@@ -385,7 +363,7 @@ class EnhancedErrors
385
363
  binding_info = convert_binding_to_binding_info(@rspec_example_binding) if @rspec_example_binding
386
364
  @capture_next_binding = false
387
365
  @rspec_example_binding = nil
388
- binding_info
366
+ return binding_info
389
367
  end
390
368
  end
391
369
 
@@ -587,7 +565,7 @@ class EnhancedErrors
587
565
  end
588
566
 
589
567
  mutex.synchronize do
590
- max_len = @max_length || DEFAULT_MAX_LENGTH
568
+ max_len = @max_capture_length || DEFAULT_MAX_CAPTURE_LENGTH
591
569
  if result.length > max_len
592
570
  result = result[0...max_len] + "... (truncated)"
593
571
  end
@@ -605,7 +583,6 @@ class EnhancedErrors
605
583
  def handle_tracepoint_event(tp)
606
584
  # Check enabled outside the synchronized block for speed, but still safe due to re-check inside.
607
585
  return unless enabled
608
- return if enforce_capture_limit
609
586
  return if Thread.current[:enhanced_errors_processing] || Thread.current[:on_capture] || ignored_exception?(tp.raised_exception)
610
587
 
611
588
  Thread.current[:enhanced_errors_processing] = true
@@ -681,7 +658,6 @@ class EnhancedErrors
681
658
 
682
659
  if binding_info
683
660
  binding_info = validate_binding_format(binding_info)
684
- increment_capture_events_count
685
661
  if binding_info && exception.binding_infos.length >= MAX_BINDING_INFOS
686
662
  exception.binding_infos.delete_at(MAX_BINDING_INFOS / 2.round)
687
663
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enhanced_errors
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Beland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-16 00:00:00.000000000 Z
11
+ date: 2024-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -84,12 +84,15 @@ files:
84
84
  - benchmark/benchmark.rb
85
85
  - benchmark/memory_bench.rb
86
86
  - benchmark/stackprofile.rb
87
+ - doc/Context.html
87
88
  - doc/Enhanced.html
88
89
  - doc/Enhanced/Colors.html
89
90
  - doc/Enhanced/Integrations.html
90
91
  - doc/Enhanced/Integrations/RSpecErrorFailureMessage.html
91
92
  - doc/EnhancedErrors.html
93
+ - doc/EnhancedExceptionContext.html
92
94
  - doc/Exception.html
95
+ - doc/ExceptionBindingInfos.html
93
96
  - doc/Minitest.html
94
97
  - doc/_index.html
95
98
  - doc/class_list.html
@@ -113,6 +116,8 @@ files:
113
116
  - examples/demo_minitest.rb
114
117
  - examples/demo_rspec.rb
115
118
  - lib/enhanced/colors.rb
119
+ - lib/enhanced/context.rb
120
+ - lib/enhanced/enhanced_exception_context.rb
116
121
  - lib/enhanced/exception.rb
117
122
  - lib/enhanced/minitest_patch.rb
118
123
  - lib/enhanced_errors.rb
@@ -136,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
141
  - !ruby/object:Gem::Version
137
142
  version: '0'
138
143
  requirements: []
139
- rubygems_version: 3.5.22
144
+ rubygems_version: 3.3.26
140
145
  signing_key:
141
146
  specification_version: 4
142
147
  summary: Automatically enhance your errors with messages containing variable values