enhanced_errors 0.1.2 → 0.1.4
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 +4 -4
- data/README.md +1 -1
- data/enhanced_errors.gemspec +1 -1
- data/examples/division_by_zero_example.rb +18 -0
- data/lib/enhanced_errors.rb +12 -8
- data/lib/error_enhancements.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8fe5b1005d924a2d75afc6603d81b9a858b44158a94f97e71381ee12f0d9f691
|
|
4
|
+
data.tar.gz: 8a574198151511f3b7774d95fb06217ba6739a258d8092724bd1fc2238071634
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5b6674b41ae75c55c5433ebd58cb3a214198183345993931f2a88e6df0eb58b2c0908ea1103c6c296a7899fb554570c65ec72d19c58377ef611718423810b83e
|
|
7
|
+
data.tar.gz: 5885b07b737a9758ec18bca9f55a7d0b305cb0b5300decd0250999dc08a2d470dcb014085db913af6fafab3b8b64e1e30dd8d6f54a5681dda491fee27fd3fb88
|
data/README.md
CHANGED
|
@@ -337,7 +337,7 @@ gem 'awesome_print'
|
|
|
337
337
|
## Performance Considerations
|
|
338
338
|
|
|
339
339
|
- **Minimal Overhead**: Since TracePoint is only activated during exception raising and rescuing, the performance impact is negligible during normal operation.
|
|
340
|
-
- **Production Safe**: The gem is designed to be safe for production use, giving you valuable insights without compromising performance.
|
|
340
|
+
- **Production Safe**: The gem is designed to be safe for production use, giving you valuable insights without compromising performance. Although this is the case, I'd still suggest letting it get well-vetted before making the leap.
|
|
341
341
|
|
|
342
342
|
## Contributing
|
|
343
343
|
|
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 = "0.1.
|
|
3
|
+
spec.version = "0.1.4"
|
|
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."
|
|
@@ -13,4 +13,22 @@ def foo
|
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
def baz
|
|
17
|
+
i.dontexist
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def boo
|
|
21
|
+
seeme = 'youshould'
|
|
22
|
+
baz
|
|
23
|
+
rescue => e
|
|
24
|
+
puts e.message
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
puts "\n--- Example with raise ---\n\n\n"
|
|
29
|
+
|
|
16
30
|
foo
|
|
31
|
+
|
|
32
|
+
puts "\n--- Example with raise and rescue (requires ruby 3.2 or greater to see rescue) ---\n\n\n"
|
|
33
|
+
|
|
34
|
+
boo
|
data/lib/enhanced_errors.rb
CHANGED
|
@@ -335,7 +335,8 @@ class EnhancedErrors
|
|
|
335
335
|
# @param binding_info [Hash] The binding information to format.
|
|
336
336
|
# @return [String] The formatted string.
|
|
337
337
|
def binding_info_string(binding_info)
|
|
338
|
-
|
|
338
|
+
capture_type = binding_info[:capture_type].to_s.capitalize
|
|
339
|
+
result = "#{Colors.red(capture_type)}: #{Colors.blue(binding_info[:source])}"
|
|
339
340
|
|
|
340
341
|
result += method_and_args_desc(binding_info[:method_and_args])
|
|
341
342
|
|
|
@@ -363,7 +364,7 @@ class EnhancedErrors
|
|
|
363
364
|
if result.length > max_length
|
|
364
365
|
result = result[0...max_length] + "... (truncated)"
|
|
365
366
|
end
|
|
366
|
-
result + "\n
|
|
367
|
+
result + "\n"
|
|
367
368
|
end
|
|
368
369
|
|
|
369
370
|
private
|
|
@@ -378,14 +379,12 @@ class EnhancedErrors
|
|
|
378
379
|
events << :rescue if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3.0')
|
|
379
380
|
|
|
380
381
|
@trace = TracePoint.new(*events) do |tp|
|
|
382
|
+
next if Thread.current[:enhanced_errors_processing] || tp.raised_exception.is_a?(NoMemoryError)
|
|
383
|
+
Thread.current[:enhanced_errors_processing] = true
|
|
381
384
|
exception = tp.raised_exception
|
|
382
385
|
capture_me = EnhancedErrors.eligible_for_capture.call(exception)
|
|
383
|
-
|
|
384
386
|
next unless capture_me
|
|
385
387
|
|
|
386
|
-
next if Thread.current[:enhanced_errors_processing]
|
|
387
|
-
Thread.current[:enhanced_errors_processing] = true
|
|
388
|
-
|
|
389
388
|
exception = tp.raised_exception
|
|
390
389
|
binding_context = tp.binding
|
|
391
390
|
|
|
@@ -445,7 +444,7 @@ class EnhancedErrors
|
|
|
445
444
|
globals: globals
|
|
446
445
|
},
|
|
447
446
|
exception: exception.class.name,
|
|
448
|
-
capture_type: capture_type
|
|
447
|
+
capture_type: capture_type.to_s
|
|
449
448
|
}
|
|
450
449
|
|
|
451
450
|
if on_capture_hook
|
|
@@ -461,6 +460,8 @@ class EnhancedErrors
|
|
|
461
460
|
else
|
|
462
461
|
puts "Invalid binding_info returned from on_capture, skipping."
|
|
463
462
|
end
|
|
463
|
+
rescue => e
|
|
464
|
+
puts "Error in TracePoint block: #{e.message}"
|
|
464
465
|
ensure
|
|
465
466
|
Thread.current[:enhanced_errors_processing] = false
|
|
466
467
|
end
|
|
@@ -472,7 +473,10 @@ class EnhancedErrors
|
|
|
472
473
|
#
|
|
473
474
|
# @return [String, nil] The current test name or `nil` if not in a test context.
|
|
474
475
|
def test_name
|
|
475
|
-
|
|
476
|
+
if defined?(RSpec)
|
|
477
|
+
return RSpec&.current_example&.full_description
|
|
478
|
+
end
|
|
479
|
+
rescue => e
|
|
476
480
|
nil
|
|
477
481
|
end
|
|
478
482
|
|
data/lib/error_enhancements.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module ErrorEnhancements
|
|
2
2
|
def message
|
|
3
3
|
original_message = super()
|
|
4
|
-
"#{original_message}#{variables_message}"
|
|
4
|
+
"#{original_message}\n#{variables_message}"
|
|
5
5
|
rescue => e
|
|
6
6
|
puts "Error in message method: #{e.message}"
|
|
7
7
|
original_message
|
|
@@ -29,6 +29,7 @@ module ErrorEnhancements
|
|
|
29
29
|
# Grab the last rescue binding if we have one
|
|
30
30
|
|
|
31
31
|
bindings_of_interest = []
|
|
32
|
+
|
|
32
33
|
binding_infos.each do |info|
|
|
33
34
|
if info[:capture_type] == 'raise' && !info[:library]
|
|
34
35
|
bindings_of_interest << info
|
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: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
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-10-
|
|
11
|
+
date: 2024-10-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: awesome_print
|