enhanced_errors 0.1.1 → 0.1.2
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
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b74f8777e19b73bcfd4024c4d3191abf98acfa397adaf99252b80cbbabf583af
|
4
|
+
data.tar.gz: 47df87c1b8820fc1f0c0bdea2abe48ad4ed817472b22d8728328b52397e21b4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1db064f46691c84d3321b735c4bbf3258aa9d6f71a1611096cbe21d9a52bd67a352cc750a2fe16ad5f9fb46911fd4111e5166f4bb08844e28b80b64ba4af7ee
|
7
|
+
data.tar.gz: cb1664d2de142e882f6d408817ac9c7a8b0bb14a54dedf30fa35fde05ba215bed7b42c17eef3109ffa4e7736f35f9eb937eac1c37a6d9a7278a6a989baff070f
|
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.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."
|
@@ -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'
|
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: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Beland
|
@@ -11,47 +11,47 @@ cert_chain: []
|
|
11
11
|
date: 2024-10-23 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.
|