enhanced_errors 3.0.3 → 3.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f31d5706d675b416846c7fe44cc1c6f6eb405489d574a9e9578aebee106109af
4
- data.tar.gz: a5d31e4545534bfba158646f30d99bae1107086c51e20d1f8a5ad77454d74c23
3
+ metadata.gz: e6463163f60ad8df047c834d0722ebfc800bbb8a9b57773d064b2a22eaeead69
4
+ data.tar.gz: 53c886d04c8b1c518d9a4d05262947f95ba462b9b3cd76cb913c2f2142080a6d
5
5
  SHA512:
6
- metadata.gz: b79305f72e59ac8c615b137b6279c74d13156085d698bcc6efaf0d6c637bd489d6bfe1e93bfc1aede2673abe60033b3e64111b07b4916b4fe880f417684bfdbd
7
- data.tar.gz: 97c791940c780ee0952e82f256b640923ba59623052224ec0c3ca5d84bf57a471f349e281cea82c0f00976dbba497a62bdc39fa5f1115d655e96baa980d0215c
6
+ metadata.gz: 4428ec99b50fd747204426fe2059b140ed335f38486babd0f5882380391490ce5c1ef4e97a55e3fcf0caceabe099c59f5813bb2be722ab7edb584278d6e06afd
7
+ data.tar.gz: e30adc9c45a925c84bc9b97f07e8a96d351325dc74880b7ee1b38f7b02e96cafec3f91b25bedafcb87793d5c11fd90aee9ec3f1bd4c426263a17a91e6ce72acf
data/README.md CHANGED
@@ -33,7 +33,6 @@ end
33
33
  <img src="./doc/images/enhanced-spec.png" style="height: 369px; width: 712px;"></img>
34
34
 
35
35
 
36
-
37
36
  The RSpec test-time only approach constrained only to test-time.
38
37
 
39
38
  ### RSpec Setup
@@ -41,31 +40,41 @@ The RSpec test-time only approach constrained only to test-time.
41
40
  Use EnhancedErrors with RSpec for test-specific exception capturing, ideal for CI and local testing without impacting production.
42
41
 
43
42
  ```ruby
43
+ # usually in spec_helper.rb or rails_helper.rb
44
44
 
45
- RSpec.configure do |config|
46
- config.before(:example) do |_example|
47
- EnhancedErrors.start_rspec_binding_capture
48
- end
49
-
50
- config.before(:example) do |_example|
51
- EnhancedErrors.start_rspec_binding_capture
52
- end
45
+ require 'enhanced_errors'
46
+ require 'awesome_print' # Optional, for better output
53
47
 
54
- config.after(:example) do |example|
55
- EnhancedErrors.override_rspec_message(example, EnhancedErrors.stop_rspec_binding_capture)
56
- end
48
+ RSpec.configure do |config|
49
+
50
+ # Along with the requires, add this to your RSpec config to enhance your RSpec output
51
+ # Consider driving the config with an environment variable like this to make it configurable per-user or run
52
+ # if ENV['enhanced_errors'] == 'true'
53
+ config.before(:example) do |_example|
54
+ EnhancedErrors.start_rspec_binding_capture
55
+ end
56
+
57
+ config.before(:example) do |_example|
58
+ EnhancedErrors.start_rspec_binding_capture
59
+ end
60
+
61
+ config.after(:example) do |example|
62
+ EnhancedErrors.override_rspec_message(example, EnhancedErrors.stop_rspec_binding_capture)
63
+ end
64
+ # end
65
+
57
66
  end
58
67
  ```
59
68
 
60
69
  <br>
61
70
 
62
-
71
+ ''''''
63
72
  ## MiniTest Setup
64
73
 
65
74
  ```ruby
66
75
  require 'enhanced_errors'
76
+ require 'awesome_print' # Optional, for better output
67
77
  require 'enhanced/minitest_patch'
68
-
69
78
  # Once the patch is loaded, it should just work!
70
79
 
71
80
  ```
@@ -127,11 +136,19 @@ EnhancedErrors.enhance_exceptions!(override_messages: true)
127
136
  <img src="./doc/images/enhanced-error.png" style="height: 215px; width: 429px;"></img>
128
137
  <br>
129
138
 
139
+ EnhancedErrors use-cases:
140
+ * Handle test and CI failures faster by skipping that pesky "reproduction" step.
141
+ * LLM-candy - Feed debug output with variable values into your LLM, making state examine-able
142
+ * Debug deep-stack errors and reduce mean time to resolution (MTTR).
143
+ * Address elusive "Heisenbugs" by capturing full error context preemptively.
144
+ * Debug cron jobs and daemons with rich, failure-specific logs.
145
+ * Catch data-driven bugs in long jobs without re-runs or extensive logging.
130
146
 
131
147
 
132
148
  ## Features
133
149
 
134
150
  - **Pure Ruby**: No external dependencies, C extensions, or C API calls.
151
+ - **Improved RSpec and Minitest errors for straight-to-fix--look-ma-no-debugging, look-ma-no-reproducing
135
152
  - **Customizable Output**: Supports multiple output formats (`:json`, `:plaintext`, `:terminal`).
136
153
  - **Flexible Hooks**: Redact or modifying captured data via the `on_capture` hook. Update the final string with on_format.
137
154
  - **Environment-Based Defaults**: For Rails apps, automatically adjusts settings based on the environment (`development`, `test`, `production`, `ci`).
@@ -141,13 +158,6 @@ EnhancedErrors.enhance_exceptions!(override_messages: true)
141
158
  - **No dependencies**: EnhancedErrors does not ___require___ any dependencies--it uses [awesome_print](https://github.com/awesome-print/awesome_print) for nicer output if it is installed and available.
142
159
  - **Lightweight**: Minimal performance impact, as tracing is only active during exception raising.
143
160
 
144
- EnhancedErrors use-cases:
145
-
146
- * Catch data-driven bugs without needing re-runs or extensive logging.
147
- * Debug deep-stack errors and reduce mean time to resolution (MTTR).
148
- * Handle CI failures faster by skipping reproduction steps.
149
- * Address elusive "Heisenbugs" by capturing error context preemptively.
150
- * Debug cron jobs and daemons with rich, failure-specific logs.
151
161
 
152
162
  ## Installation
153
163
 
@@ -218,9 +228,6 @@ EnhancedErrors adjusts its default settings based on the environment:
218
228
  - **Development/Test**:
219
229
  - Default Output format: `:terminal`
220
230
  - Terminal Color output: Enabled
221
- - **Production**:
222
- - Output format: `:json`
223
- - Terminal Color output: Disabled
224
231
  - **CI Environment**:
225
232
  - Output format: `:plaintext`
226
233
  - Color output: Disabled
@@ -332,10 +339,6 @@ These exceptions are always ignored:
332
339
 
333
340
  ```ruby
334
341
  SystemExit NoMemoryError SignalException Interrupt
335
- ScriptError LoadError NotImplementedError SyntaxError
336
- RSpec::Expectations::ExpectationNotMetError
337
- RSpec::Matchers::BuiltIn::RaiseError
338
- SystemStackError Psych::BadAlias
339
342
  ```
340
343
 
341
344
  While this is close to "Things that don't descend from StandardError", it's not exactly that.
@@ -429,9 +432,9 @@ To make that work, it has to be able to safely be 'on' ahead of time, and gather
429
432
  a way I naturally will retain without requiring extra preparation I obviously didn't know to do.
430
433
 
431
434
  - EnhancedErrors won't interrupt CI, but it lets me know what happened _without_ reproduction steps
432
- - EnhancedErrors could, theoretically, also be fine in production (if data security, redaction,
433
- PII, access, and encryption concerns were all addressed.
434
- Big list, but another option is to selectively enable targeted capture.
435
+ - EnhancedErrors could, theoretically, be fine in production (if data security, redaction,
436
+ PII, access, and encryption concerns were addressed). Big list, but another option is to selectively enable targeted capture.
437
+ The hooks provide a place to handle things of this sort.
435
438
  - Has decent performance characteristics
436
439
  - **Only** becomes active in exception raise/rescue scenarios
437
440
 
@@ -445,14 +448,19 @@ Exceptions. It operates in a narrow scope--becoming active only when exceptions
445
448
 
446
449
  - **Small Overhead**: Since TracePoint is only activated during exception raising and rescuing, the performance impact is negligible during normal operation. (Benchmark included)
447
450
 
448
- - **TBD**: Memory considerations. This does capture data when an exception happens. EnhancedErrors hides under the bed when it sees **NoMemoryError**.
451
+ - **TBD**: Memory considerations. This does capture data when an exception happens. EnhancedErrors hides under the bed
452
+ when it sees the scariest exceptions.
449
453
 
450
- - **Goal: Production Safety**: The gem is designed to, eventually, be made safe for production use, giving you valuable insights without compromising performance.
451
- I would not enable it in production *yet*.
454
+ - **Goal: Production Safety**: The gem is designed to, eventually, be suitable for production use.
455
+ I might not enable it in production *yet* as it is pretty new. It would require
456
+ a thoughtful approach (perhaps behind a feature flag, or only capturing targeted exceptions
457
+ via the eligible for capture feature).
452
458
 
453
459
  ## Contributing
454
460
 
455
- Bug reports and pull requests are welcome on GitHub at [https://github.com/your_username/enhanced_errors](https://github.com/your_username/enhanced_errors).
461
+ Bug reports and pull requests are welcome on GitHub.
462
+
463
+ * Please include tests to demonstrate your contribution working.
456
464
 
457
465
  ## License
458
466
 
@@ -1,8 +1,15 @@
1
1
  require 'benchmark'
2
- require_relative '../lib/enhanced/enhanced' # Adjust the path if necessary
2
+ require_relative '../lib/enhanced_errors' # Adjust the path if necessary
3
+
4
+ #require 'profile'
5
+
6
+ # In general, the results of this are--catching exception bindings is pretty cheap.
7
+ # However, catching :call, :return, :b_return, :b_call are 100x more expensive.
8
+ # Makes sense if you think about the relative frequency of things.
9
+
3
10
 
4
11
  # Define the number of iterations
5
- ITERATIONS = 10_000
12
+ ITERATIONS = 1_000
6
13
  EXCEPTIONS_PER_BATCH = 100
7
14
 
8
15
  class Boo < StandardError; end
@@ -12,20 +19,8 @@ def calculate_cost(time_in_seconds)
12
19
  (milliseconds / (ITERATIONS / EXCEPTIONS_PER_BATCH)).round(2)
13
20
  end
14
21
 
15
- def with_enhanced_errors
16
- EnhancedErrors.enhance_exceptions!(debug: false)
17
- ITERATIONS.times do
18
- begin
19
- foo = 'bar'
20
- @boo = 'baz'
21
- raise 'Test exception with EnhancedErrors'
22
- rescue => e
23
- e.message
24
- end
25
- end
26
- end
27
22
 
28
- def without_enhanced_errors
23
+ def raise_errors
29
24
  ITERATIONS.times do
30
25
  begin
31
26
  foo = 'bar'
@@ -38,8 +33,9 @@ def without_enhanced_errors
38
33
  end
39
34
 
40
35
  def when_capture_only_regexp_matched
36
+ rxp = /Boo/
41
37
  EnhancedErrors.enhance_exceptions!(debug: false) do
42
- eligible_for_capture { |exception| !!/Boo/.match(exception.class.to_s) }
38
+ eligible_for_capture { |exception| !!rxp.match(exception.class.to_s) }
43
39
  end
44
40
 
45
41
  ITERATIONS.times do
@@ -54,8 +50,9 @@ def when_capture_only_regexp_matched
54
50
  end
55
51
 
56
52
  def when_capture_only_regexp_did_not_match
57
- EnhancedErrors.enhance_exceptions!(debug: false) do
58
- eligible_for_capture { |exception| !!/Baz/.match(exception.class.to_s) }
53
+ rxp = /Baz/
54
+ EnhancedErrors.enhance_exceptions!(override_messages: true) do
55
+ eligible_for_capture { |exception| !!rxp.match(exception.class.to_s) }
59
56
  end
60
57
 
61
58
  ITERATIONS.times do
@@ -71,18 +68,23 @@ end
71
68
 
72
69
  puts "Cost Exploration\n"
73
70
  Benchmark.bm(35) do |x|
74
- without_time = x.report('10k Without EnhancedErrors:') { without_enhanced_errors }
75
- with_time = x.report('10k With EnhancedErrors:') { with_enhanced_errors }
76
-
77
- puts "\nCost per 100 exceptions (Without EnhancedErrors): #{calculate_cost(without_time.real)} ms"
78
- puts "Cost per 100 exceptions (With EnhancedErrors): #{calculate_cost(with_time.real)} ms"
71
+ without_time = x.report('Baseline 1k (NO EnhancedErrors, tight error raise loop):') { raise_errors }
79
72
  end
80
73
 
81
- puts "\nProof that if you only match the classes you care about, the cost is nominal\n"
82
- Benchmark.bm(35) do |x|
83
- matched_time = x.report('10k With capture_only_regexp match:') { when_capture_only_regexp_matched }
84
- not_matched_time = x.report('10k Without capture_only_regexp match:') { when_capture_only_regexp_did_not_match }
74
+ puts "\n"
75
+ EnhancedErrors.enhance_exceptions!(debug: false)
85
76
 
86
- puts "\nCost per 100 exceptions (Capture Only Match): #{calculate_cost(matched_time.real)} ms"
87
- puts "Cost per 100 exceptions (No Match): #{calculate_cost(not_matched_time.real)} ms"
77
+ Benchmark.bm(35) do |x|
78
+ with_time = x.report('Stress 1k EnhancedErrors (Tight error raising loop w/ EnhancedErrors):') { raise_errors }
79
+ puts "Cost per 100 raised exceptions: #{calculate_cost(with_time.real)} ms"
88
80
  end
81
+
82
+
83
+ # puts "\nProof that if you only match the classes you care about, the cost is nominal\n"
84
+ # Benchmark.bm(35) do |x|
85
+ # matched_time = x.report('1k capture_only_regexp match (same as always-on) :') { when_capture_only_regexp_matched }
86
+ # not_matched_time = x.report('1k capture_only_regexp not matching (low-cost):') { when_capture_only_regexp_did_not_match }
87
+ #
88
+ # puts "\nCost per 100 exceptions (Capture Only Match): #{calculate_cost(matched_time.real)} ms"
89
+ # puts "Cost per 100 exceptions (No Match): #{calculate_cost(not_matched_time.real)} ms"
90
+ # end
@@ -71,7 +71,7 @@ def test_exception_with_large_variable(iterations, large_string)
71
71
  puts "Memory usage after exceptions: #{memory_usage} KB"
72
72
  end
73
73
 
74
- iterations = 10 # Adjust iterations as needed
74
+ iterations = 10000 # Adjust iterations as needed
75
75
 
76
76
  test_with_tracepoint(iterations, large_string)
77
77
  test_without_tracepoint(iterations, large_string)
@@ -0,0 +1,11 @@
1
+ Result from MacOs, Ruby 3.3.6 for benchmark.rb
2
+
3
+ --------------------------------------------
4
+
5
+ Cost Exploration
6
+ user system total real
7
+ Baseline 1k (NO EnhancedErrors, tight error raise loop): 0.000386 0.000049 0.000435 ( 0.000434)
8
+
9
+ user system total real
10
+ Stress 1k EnhancedErrors (Tight error raising loop w/ EnhancedErrors): 0.007653 0.000241 0.007894 ( 0.007894)
11
+ Cost per 100 raised exceptions: 0.79 ms
@@ -381,9 +381,9 @@
381
381
  </div>
382
382
 
383
383
  <div id="footer">
384
- Generated on Tue Dec 17 21:43:58 2024 by
384
+ Generated on Wed Dec 25 13:01:48 2024 by
385
385
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
386
- 0.9.37 (ruby-3.3.6).
386
+ 0.9.37 (ruby-3.4.1).
387
387
  </div>
388
388
 
389
389
  </div>
@@ -0,0 +1,283 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Class: Enhanced::Context
8
+
9
+ &mdash; Documentation by YARD 0.9.37
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "Enhanced::Context";
19
+ relpath = '../';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="../class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="../_index.html">Index (C)</a> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../Enhanced.html" title="Enhanced (module)">Enhanced</a></span></span>
41
+ &raquo;
42
+ <span class="title">Context</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="../class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Class: Enhanced::Context
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+ <dl>
70
+ <dt>Inherits:</dt>
71
+ <dd>
72
+ <span class="inheritName">Object</span>
73
+
74
+ <ul class="fullTree">
75
+ <li>Object</li>
76
+
77
+ <li class="next">Enhanced::Context</li>
78
+
79
+ </ul>
80
+ <a href="#" class="inheritanceTree">show all</a>
81
+
82
+ </dd>
83
+ </dl>
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+ <dl>
96
+ <dt>Defined in:</dt>
97
+ <dd>lib/enhanced/context.rb</dd>
98
+ </dl>
99
+
100
+ </div>
101
+
102
+
103
+
104
+
105
+
106
+ <h2>Instance Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2>
107
+ <ul class="summary">
108
+
109
+ <li class="public ">
110
+ <span class="summary_signature">
111
+
112
+ <a href="#binding_infos-instance_method" title="#binding_infos (instance method)">#<strong>binding_infos</strong> &#x21d2; Object </a>
113
+
114
+
115
+
116
+ </span>
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+ <span class="summary_desc"><div class='inline'>
130
+ <p>Returns the value of attribute binding_infos.</p>
131
+ </div></span>
132
+
133
+ </li>
134
+
135
+
136
+ </ul>
137
+
138
+
139
+
140
+
141
+
142
+ <h2>
143
+ Instance Method Summary
144
+ <small><a href="#" class="summary_toggle">collapse</a></small>
145
+ </h2>
146
+
147
+ <ul class="summary">
148
+
149
+ <li class="public ">
150
+ <span class="summary_signature">
151
+
152
+ <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong> &#x21d2; Context </a>
153
+
154
+
155
+
156
+ </span>
157
+
158
+
159
+ <span class="note title constructor">constructor</span>
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+ <span class="summary_desc"><div class='inline'>
169
+ <p>A new instance of Context.</p>
170
+ </div></span>
171
+
172
+ </li>
173
+
174
+
175
+ </ul>
176
+
177
+
178
+ <div id="constructor_details" class="method_details_list">
179
+ <h2>Constructor Details</h2>
180
+
181
+ <div class="method_details first">
182
+ <h3 class="signature first" id="initialize-instance_method">
183
+
184
+ #<strong>initialize</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Enhanced::Context (class)">Context</a></span></tt>
185
+
186
+
187
+
188
+
189
+
190
+ </h3><div class="docstring">
191
+ <div class="discussion">
192
+
193
+ <p>Returns a new instance of Context.</p>
194
+
195
+
196
+ </div>
197
+ </div>
198
+ <div class="tags">
199
+
200
+
201
+ </div><table class="source_code">
202
+ <tr>
203
+ <td>
204
+ <pre class="lines">
205
+
206
+
207
+ 5
208
+ 6
209
+ 7</pre>
210
+ </td>
211
+ <td>
212
+ <pre class="code"><span class="info file"># File 'lib/enhanced/context.rb', line 5</span>
213
+
214
+ <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
215
+ <span class='ivar'>@binding_infos</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
216
+ <span class='kw'>end</span></pre>
217
+ </td>
218
+ </tr>
219
+ </table>
220
+ </div>
221
+
222
+ </div>
223
+
224
+ <div id="instance_attr_details" class="attr_details">
225
+ <h2>Instance Attribute Details</h2>
226
+
227
+
228
+ <span id="binding_infos=-instance_method"></span>
229
+ <div class="method_details first">
230
+ <h3 class="signature first" id="binding_infos-instance_method">
231
+
232
+ #<strong>binding_infos</strong> &#x21d2; <tt>Object</tt>
233
+
234
+
235
+
236
+
237
+
238
+ </h3><div class="docstring">
239
+ <div class="discussion">
240
+
241
+ <p>Returns the value of attribute binding_infos.</p>
242
+
243
+
244
+ </div>
245
+ </div>
246
+ <div class="tags">
247
+
248
+
249
+ </div><table class="source_code">
250
+ <tr>
251
+ <td>
252
+ <pre class="lines">
253
+
254
+
255
+ 3
256
+ 4
257
+ 5</pre>
258
+ </td>
259
+ <td>
260
+ <pre class="code"><span class="info file"># File 'lib/enhanced/context.rb', line 3</span>
261
+
262
+ <span class='kw'>def</span> <span class='id identifier rubyid_binding_infos'>binding_infos</span>
263
+ <span class='ivar'>@binding_infos</span>
264
+ <span class='kw'>end</span></pre>
265
+ </td>
266
+ </tr>
267
+ </table>
268
+ </div>
269
+
270
+ </div>
271
+
272
+
273
+ </div>
274
+
275
+ <div id="footer">
276
+ Generated on Wed Dec 25 13:01:48 2024 by
277
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
278
+ 0.9.37 (ruby-3.4.1).
279
+ </div>
280
+
281
+ </div>
282
+ </body>
283
+ </html>