enhanced_errors 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -53
- data/doc/images/enhanced-error.png +0 -0
- data/doc/images/enhanced-spec.png +0 -0
- data/enhanced_errors.gemspec +5 -4
- data/examples/example_spec.rb +2 -2
- data/lib/enhanced_errors.rb +8 -4
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1c7e272782dc0e8d9b0d41ae7836fe1c4f21a1278e8f7166d778abe6027de01
|
4
|
+
data.tar.gz: 5c2d742bfe53aa52a889c160267820a1439f8905e3329acd962be5c37ad8eab4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 702f2835ec5cc4cb9b92223ba7a3d88636fc8d9dc0e2f2d82a69d1956fd0e81363b18ff272b1b342b7af4147b1d980835e432ce01164b37e7e3ec591595b6862
|
7
|
+
data.tar.gz: ae0de7863558ef646236ef8c53f54b41ed0bf6cfb917a3f2e00f4561afed20f0a2e4d4f5b9178b47c1e483d09acb314a5679ba4f3c34b5ca1e443987429ef6cb
|
data/README.md
CHANGED
@@ -34,38 +34,36 @@ foo
|
|
34
34
|
|
35
35
|
##### Output:
|
36
36
|
|
37
|
-
<img src="./doc/images/enhanced-error.png" style="height:
|
38
|
-
|
37
|
+
<img src="./doc/images/enhanced-error.png" style="height: 215px; width: 429px;"></img>
|
39
38
|
<br>
|
40
|
-
|
41
39
|
#### Enhanced Exception In Specs:
|
42
40
|
|
43
41
|
```ruby
|
44
|
-
|
45
|
-
let(:the_matrix) { 'code rains, dramatically' }
|
42
|
+
describe 'sees through' do
|
46
43
|
|
47
|
-
|
48
|
-
@spoon = 'there is no spoon'
|
49
|
-
end
|
44
|
+
let(:the_matrix) { 'code rains, dramatically' }
|
50
45
|
|
51
|
-
|
52
|
-
|
53
|
-
the_matrix
|
54
|
-
stop = 'bullets'
|
55
|
-
raise 'No!'
|
56
|
-
end
|
46
|
+
before(:each) do
|
47
|
+
@spoon = 'there is no spoon'
|
57
48
|
end
|
49
|
+
|
50
|
+
it 'the matrix' do
|
51
|
+
#activate memoized item
|
52
|
+
the_matrix
|
53
|
+
stop = 'bullets'
|
54
|
+
raise 'No!'
|
55
|
+
end
|
56
|
+
end
|
58
57
|
```
|
59
58
|
|
60
59
|
#### Output:
|
61
60
|
|
62
|
-
<img src="./doc/images/enhanced-spec.png" style="height:
|
61
|
+
<img src="./doc/images/enhanced-spec.png" style="height: 369px; width: 712px;"></img>
|
63
62
|
|
64
63
|
|
65
64
|
## Features
|
66
65
|
|
67
|
-
- **Pure Ruby**: No external dependencies or C
|
68
|
-
- **Standalone**: Does not rely on any external libraries.
|
66
|
+
- **Pure Ruby**: No external dependencies, C extensions, or C API calls.
|
69
67
|
- **Lightweight**: Minimal performance impact, as tracing is only active during exception raising.
|
70
68
|
- **Customizable Output**: Supports multiple output formats (`:json`, `:plaintext`, `:terminal`).
|
71
69
|
- **Flexible Hooks**: Redact or modifying captured data via the `on_capture` hook.
|
@@ -149,6 +147,10 @@ end
|
|
149
147
|
- `enabled`: Enables or disables the enhancement (default: `true`).
|
150
148
|
- `max_length`: Sets the maximum length of the enhanced message (default: `2500`).
|
151
149
|
|
150
|
+
Currently, the first `raise` exception binding is presented.
|
151
|
+
This may be changed in the future to allow more binding data to be presented.
|
152
|
+
|
153
|
+
|
152
154
|
### Environment-Based Defaults
|
153
155
|
|
154
156
|
EnhancedErrors adjusts its default settings based on the environment:
|
@@ -265,14 +267,13 @@ The skip list is pre-populated with common variables to exclude and can be exten
|
|
265
267
|
|
266
268
|
|
267
269
|
|
268
|
-
|
269
270
|
### Capture Levels
|
270
271
|
|
271
272
|
EnhancedErrors supports different capture levels to control the verbosity of the captured data:
|
272
273
|
|
273
274
|
- **Info Level**: Respects the skip list, excluding predefined sensitive or irrelevant variables. Global variables are ignored.
|
274
275
|
- **Debug Level**: Ignores the skip lists, capturing all variables including those typically excluded and global variables.
|
275
|
-
Global variables,
|
276
|
+
Global variables are only captured in debug mode, and they exclude the default Ruby global variables.
|
276
277
|
|
277
278
|
**Default Behavior**: By default, `info` level is used, which excludes variables in the skip list to protect sensitive information. In `debug` 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.
|
278
279
|
The info mode is recommended.
|
@@ -287,7 +288,7 @@ EnhancedErrors differentiates between two types of capture events:
|
|
287
288
|
- **`rescue`**: Captures the context when an exception is last rescued.
|
288
289
|
|
289
290
|
**Default Behavior**: By default, EnhancedErrors returns the first `raise` and the last `rescue` event for each exception.
|
290
|
-
|
291
|
+
The `rescue` exception is only available in Ruby 3.2+ as it was added to TracePoint events in Ruby 3.2.
|
291
292
|
|
292
293
|
|
293
294
|
### Example: Redacting Sensitive Information
|
@@ -304,39 +305,6 @@ EnhancedErrors.on_capture do |binding_info|
|
|
304
305
|
end
|
305
306
|
```
|
306
307
|
|
307
|
-
### Example: Encrypting Data in Custom Format
|
308
|
-
|
309
|
-
|
310
|
-
```ruby
|
311
|
-
# config/initializers/encryption.rb
|
312
|
-
|
313
|
-
require 'active_support'
|
314
|
-
|
315
|
-
# Retrieve the encryption key from Rails credentials or environment variables
|
316
|
-
ENCRYPTION_KEY = Rails.application.credentials.encryption_key || ENV['ENCRYPTION_KEY']
|
317
|
-
|
318
|
-
# It's recommended to use a 256-bit key (32 bytes)
|
319
|
-
# If your key is in hex or another format, ensure it's properly decoded
|
320
|
-
key = ActiveSupport::KeyGenerator.new(ENCRYPTION_KEY).generate_key('enhanced_errors', 32)
|
321
|
-
ENCRYPTOR = ActiveSupport::MessageEncryptor.new(key)
|
322
|
-
```
|
323
|
-
|
324
|
-
```ruby
|
325
|
-
|
326
|
-
require_relative 'path_to/enhanced_errors' # Adjust the path accordingly
|
327
|
-
require 'active_support/message_encryptor'
|
328
|
-
|
329
|
-
# Ensure the encryptor is initialized
|
330
|
-
encryptor = ENCRYPTOR
|
331
|
-
|
332
|
-
EnhancedErrors.on_format = lambda do |formatted_string|
|
333
|
-
encrypted_data = encryptor.encrypt_and_sign(formatted_string)
|
334
|
-
encrypted_base64 = Base64.strict_encode64(encrypted_data)
|
335
|
-
"ENCRYPTED[#{encrypted_base64}]"
|
336
|
-
end
|
337
|
-
```
|
338
|
-
|
339
|
-
|
340
308
|
## How It Works
|
341
309
|
|
342
310
|
EnhancedErrors uses Ruby's `TracePoint` to listen for `:raise` and `:rescue` events.
|
Binary file
|
Binary file
|
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.3"
|
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."
|
@@ -20,7 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
spec.require_paths = ["lib"]
|
23
|
-
|
24
|
-
spec.add_development_dependency "awesome_print", "
|
25
|
-
spec.add_development_dependency "
|
23
|
+
|
24
|
+
spec.add_development_dependency "awesome_print", "~> 1.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "yard", "> 0.9"
|
26
27
|
end
|
data/examples/example_spec.rb
CHANGED
@@ -10,14 +10,14 @@ RSpec.describe 'Neo' do
|
|
10
10
|
EnhancedErrors.enhance!
|
11
11
|
end
|
12
12
|
|
13
|
-
describe '
|
13
|
+
describe 'sees through' do
|
14
14
|
let(:the_matrix) { 'code rains, dramatically' }
|
15
15
|
|
16
16
|
before(:each) do
|
17
17
|
@spoon = 'there is no spoon'
|
18
18
|
end
|
19
19
|
|
20
|
-
it '
|
20
|
+
it 'the matrix' do
|
21
21
|
#activate memoized item
|
22
22
|
the_matrix
|
23
23
|
stop = 'bullets'
|
data/lib/enhanced_errors.rb
CHANGED
@@ -378,13 +378,12 @@ class EnhancedErrors
|
|
378
378
|
events << :rescue if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3.0')
|
379
379
|
|
380
380
|
@trace = TracePoint.new(*events) do |tp|
|
381
|
+
next if Thread.current[:enhanced_errors_processing]
|
382
|
+
Thread.current[:enhanced_errors_processing] = true
|
381
383
|
exception = tp.raised_exception
|
382
384
|
capture_me = EnhancedErrors.eligible_for_capture.call(exception)
|
383
|
-
|
384
385
|
next unless capture_me
|
385
386
|
|
386
|
-
next if Thread.current[:enhanced_errors_processing]
|
387
|
-
Thread.current[:enhanced_errors_processing] = true
|
388
387
|
|
389
388
|
exception = tp.raised_exception
|
390
389
|
binding_context = tp.binding
|
@@ -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
|
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
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.3
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: awesome_print
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '1.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '3.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '3.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: yard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.9
|
47
|
+
version: '0.9'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.9
|
54
|
+
version: '0.9'
|
55
55
|
description: With no extra dependencies, and using only Ruby's built-in TracePoint,
|
56
56
|
EnhancedErrors will automatically enhance your errors with messages containing variable
|
57
57
|
values from the moment they were raised.
|