enhanced_errors 0.1.4 → 0.1.6

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.
@@ -172,16 +172,22 @@
172
172
  5
173
173
  6
174
174
  7
175
- 8</pre>
175
+ 8
176
+ 9
177
+ 10
178
+ 11</pre>
176
179
  </td>
177
180
  <td>
178
181
  <pre class="code"><span class="info file"># File 'lib/error_enhancements.rb', line 2</span>
179
182
 
180
183
  <span class='kw'>def</span> <span class='id identifier rubyid_message'>message</span>
181
184
  <span class='id identifier rubyid_original_message'>original_message</span> <span class='op'>=</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='rparen'>)</span>
182
- <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_original_message'>original_message</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_variables_message'>variables_message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
185
+ <span class='kw'>if</span> <span class='id identifier rubyid_original_message'>original_message</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_variables_message'>variables_message</span><span class='rparen'>)</span>
186
+ <span class='id identifier rubyid_original_message'>original_message</span>
187
+ <span class='kw'>else</span>
188
+ <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_original_message'>original_message</span><span class='embexpr_end'>}</span><span class='tstring_content'>\n</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_variables_message'>variables_message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
189
+ <span class='kw'>end</span>
183
190
  <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
184
- <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Error in message method: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
185
191
  <span class='id identifier rubyid_original_message'>original_message</span>
186
192
  <span class='kw'>end</span></pre>
187
193
  </td>
@@ -204,9 +210,6 @@
204
210
  <pre class="lines">
205
211
 
206
212
 
207
- 10
208
- 11
209
- 12
210
213
  13
211
214
  14
212
215
  15
@@ -215,10 +218,13 @@
215
218
  18
216
219
  19
217
220
  20
218
- 21</pre>
221
+ 21
222
+ 22
223
+ 23
224
+ 24</pre>
219
225
  </td>
220
226
  <td>
221
- <pre class="code"><span class="info file"># File 'lib/error_enhancements.rb', line 10</span>
227
+ <pre class="code"><span class="info file"># File 'lib/error_enhancements.rb', line 13</span>
222
228
 
223
229
  <span class='kw'>def</span> <span class='id identifier rubyid_variables_message'>variables_message</span>
224
230
  <span class='ivar'>@variables_message</span> <span class='op'>||=</span> <span class='kw'>begin</span>
@@ -242,7 +248,7 @@
242
248
  </div>
243
249
 
244
250
  <div id="footer">
245
- Generated on Tue Oct 22 23:16:25 2024 by
251
+ Generated on Sun Nov 10 12:01:14 2024 by
246
252
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
247
253
  0.9.37 (ruby-3.1.3).
248
254
  </div>
data/doc/_index.html CHANGED
@@ -141,7 +141,7 @@
141
141
  </div>
142
142
 
143
143
  <div id="footer">
144
- Generated on Tue Oct 22 23:16:24 2024 by
144
+ Generated on Sun Nov 10 12:01:13 2024 by
145
145
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
146
146
  0.9.37 (ruby-3.1.3).
147
147
  </div>
data/doc/file.README.html CHANGED
@@ -91,37 +91,34 @@
91
91
 
92
92
  <h5 id="label-Output-3A">Output:</h5>
93
93
 
94
- <p>&lt;img src=“./doc/images/enhanced-error.png” style=“height: 171px; width: 440px;”&gt;&lt;/img&gt;</p>
95
-
96
- <p><br></p>
94
+ <p>&lt;img src=“./doc/images/enhanced-error.png” style=“height: 215px; width: 429px;”&gt;&lt;/img&gt; <br></p>
97
95
 
98
96
  <h4 id="label-Enhanced+Exception+In+Specs-3A">Enhanced Exception In Specs:</h4>
99
97
 
100
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_describe'>describe</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>attains enlightenment</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>do</span>
101
- <span class='id identifier rubyid_let'>let</span><span class='lparen'>(</span><span class='symbol'>:the_matrix</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>code rains, dramatically</span><span class='tstring_end'>&#39;</span></span> <span class='rbrace'>}</span>
98
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_describe'>describe</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>sees through</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>do</span>
102
99
 
103
- <span class='id identifier rubyid_before'>before</span><span class='lparen'>(</span><span class='symbol'>:each</span><span class='rparen'>)</span> <span class='kw'>do</span>
104
- <span class='ivar'>@spoon</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>there is no spoon</span><span class='tstring_end'>&#39;</span></span>
105
- <span class='kw'>end</span>
100
+ <span class='id identifier rubyid_let'>let</span><span class='lparen'>(</span><span class='symbol'>:the_matrix</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>code rains, dramatically</span><span class='tstring_end'>&#39;</span></span> <span class='rbrace'>}</span>
106
101
 
107
- <span class='id identifier rubyid_it'>it</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>in the matrix</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>do</span>
108
- <span class='comment'>#activate memoized item
109
- </span> <span class='id identifier rubyid_the_matrix'>the_matrix</span>
110
- <span class='id identifier rubyid_stop'>stop</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>bullets</span><span class='tstring_end'>&#39;</span></span>
111
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>No!</span><span class='tstring_end'>&#39;</span></span>
112
- <span class='kw'>end</span>
102
+ <span class='id identifier rubyid_before'>before</span><span class='lparen'>(</span><span class='symbol'>:each</span><span class='rparen'>)</span> <span class='kw'>do</span>
103
+ <span class='ivar'>@spoon</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>there is no spoon</span><span class='tstring_end'>&#39;</span></span>
113
104
  <span class='kw'>end</span>
105
+
106
+ <span class='id identifier rubyid_it'>it</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>the matrix</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>do</span>
107
+ <span class='comment'>#activate memoized item
108
+ </span> <span class='id identifier rubyid_the_matrix'>the_matrix</span>
109
+ <span class='id identifier rubyid_stop'>stop</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>bullets</span><span class='tstring_end'>&#39;</span></span>
110
+ <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>No!</span><span class='tstring_end'>&#39;</span></span>
111
+ <span class='kw'>end</span>
112
+ <span class='kw'>end</span>
114
113
  </code></pre>
115
114
 
116
115
  <h4 id="label-Output-3A">Output:</h4>
117
116
 
118
- <p>&lt;img src=“./doc/images/enhanced-spec.png” style=“height: 426px; width: 712px;”&gt;&lt;/img&gt;</p>
117
+ <p>&lt;img src=“./doc/images/enhanced-spec.png” style=“height: 369px; width: 712px;”&gt;&lt;/img&gt;</p>
119
118
 
120
119
  <h2 id="label-Features">Features</h2>
121
120
  <ul><li>
122
- <p><strong>Pure Ruby</strong>: No external dependencies or C extensions.</p>
123
- </li><li>
124
- <p><strong>Standalone</strong>: Does not rely on any external libraries.</p>
121
+ <p><strong>Pure Ruby</strong>: No external dependencies, C extensions, or C API calls.</p>
125
122
  </li><li>
126
123
  <p><strong>Lightweight</strong>: Minimal performance impact, as tracing is only active during exception raising.</p>
127
124
  </li><li>
@@ -208,6 +205,8 @@
208
205
  <p><code>max_length</code>: Sets the maximum length of the enhanced message (default: <code>2500</code>).</p>
209
206
  </li></ul>
210
207
 
208
+ <p>Currently, the first <code>raise</code> exception binding is presented. This may be changed in the future to allow more binding data to be presented.</p>
209
+
211
210
  <h3 id="label-Environment-Based+Defaults">Environment-Based Defaults</h3>
212
211
 
213
212
  <p>EnhancedErrors adjusts its default settings based on the environment:</p>
@@ -270,7 +269,7 @@
270
269
  globals: globals
271
270
  },
272
271
  exception: exception.class.name,
273
- capture_type: capture_type # &#39;raise&#39; or &#39;rescue&#39;
272
+ capture_event: capture_event # &#39;raise&#39; or &#39;rescue&#39;
274
273
  }
275
274
  </code></pre>
276
275
 
@@ -315,13 +314,32 @@
315
314
 
316
315
  <p>The skip list is pre-populated with common variables to exclude and can be extended based on your application’s requirements.</p>
317
316
 
317
+ <h4 id="label-Capture+Rules">Capture Rules</h4>
318
+
319
+ <p>These exceptions are always ignored:</p>
320
+
321
+ <pre class="code ruby"><code class="ruby">SystemExit,
322
+ NoMemoryError,
323
+ SignalException,
324
+ Interrupt,
325
+ ScriptError,
326
+ LoadError,
327
+ NotImplementedError,
328
+ SyntaxError,
329
+ SystemStackError
330
+ </code></pre>
331
+
332
+ <p>While this is close to “Things that don’t descend from StandardError”, it’s not exactly that.</p>
333
+
334
+ <p>In Info mode, variables starting with @_ are also ignored.</p>
335
+
318
336
  <h3 id="label-Capture+Levels">Capture Levels</h3>
319
337
 
320
338
  <p>EnhancedErrors supports different capture levels to control the verbosity of the captured data:</p>
321
339
  <ul><li>
322
340
  <p><strong>Info Level</strong>: Respects the skip list, excluding predefined sensitive or irrelevant variables. Global variables are ignored.</p>
323
341
  </li><li>
324
- <p><strong>Debug Level</strong>: Ignores the skip lists, capturing all variables including those typically excluded and global variables. Global variables,</p>
342
+ <p><strong>Debug Level</strong>: Ignores the skip lists, capturing all variables including those typically excluded and global variables. Global variables are only captured in debug mode, and they exclude the default Ruby global variables.</p>
325
343
  </li></ul>
326
344
 
327
345
  <p><strong>Default Behavior</strong>: By default, <code>info</code> level is used, which excludes variables in the skip list to protect sensitive information. In <code>debug</code> 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. The info mode is recommended.</p>
@@ -335,7 +353,7 @@
335
353
  <p><strong><code>rescue</code></strong>: Captures the context when an exception is last rescued.</p>
336
354
  </li></ul>
337
355
 
338
- <p><strong>Default Behavior</strong>: By default, EnhancedErrors returns the first <code>raise</code> and the last <code>rescue</code> event for each exception. This provides a clear picture of where and how the exception was handled.</p>
356
+ <p><strong>Default Behavior</strong>: By default, EnhancedErrors returns the first <code>raise</code> and the last <code>rescue</code> event for each exception. The <code>rescue</code> exception is only available in Ruby 3.2+ as it was added to TracePoint events in Ruby 3.2.</p>
339
357
 
340
358
  <h3 id="label-Example-3A+Redacting+Sensitive+Information">Example: Redacting Sensitive Information</h3>
341
359
 
@@ -350,35 +368,6 @@
350
368
  <span class='kw'>end</span>
351
369
  </code></pre>
352
370
 
353
- <h3 id="label-Example-3A+Encrypting+Data+in+Custom+Format">Example: Encrypting Data in Custom Format</h3>
354
-
355
- <pre class="code ruby"><code class="ruby"><span class='comment'># config/initializers/encryption.rb
356
- </span>
357
- <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>active_support</span><span class='tstring_end'>&#39;</span></span>
358
-
359
- <span class='comment'># Retrieve the encryption key from Rails credentials or environment variables
360
- </span><span class='const'>ENCRYPTION_KEY</span> <span class='op'>=</span> <span class='const'>Rails</span><span class='period'>.</span><span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_credentials'>credentials</span><span class='period'>.</span><span class='id identifier rubyid_encryption_key'>encryption_key</span> <span class='op'>||</span> <span class='const'>ENV</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ENCRYPTION_KEY</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span>
361
-
362
- <span class='comment'># It&#39;s recommended to use a 256-bit key (32 bytes)
363
- </span><span class='comment'># If your key is in hex or another format, ensure it&#39;s properly decoded
364
- </span><span class='id identifier rubyid_key'>key</span> <span class='op'>=</span> <span class='const'>ActiveSupport</span><span class='op'>::</span><span class='const'>KeyGenerator</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>ENCRYPTION_KEY</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_generate_key'>generate_key</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>enhanced_errors</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='int'>32</span><span class='rparen'>)</span>
365
- <span class='const'>ENCRYPTOR</span> <span class='op'>=</span> <span class='const'>ActiveSupport</span><span class='op'>::</span><span class='const'>MessageEncryptor</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
366
- </code></pre>
367
-
368
- <pre class="code ruby"><code class="ruby">
369
- <span class='id identifier rubyid_require_relative'>require_relative</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>path_to/enhanced_errors</span><span class='tstring_end'>&#39;</span></span> <span class='comment'># Adjust the path accordingly
370
- </span><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>active_support/message_encryptor</span><span class='tstring_end'>&#39;</span></span>
371
-
372
- <span class='comment'># Ensure the encryptor is initialized
373
- </span><span class='id identifier rubyid_encryptor'>encryptor</span> <span class='op'>=</span> <span class='const'>ENCRYPTOR</span>
374
-
375
- <span class='const'><span class='object_link'><a href="EnhancedErrors.html" title="EnhancedErrors (class)">EnhancedErrors</a></span></span><span class='period'>.</span><span class='id identifier rubyid_on_format'><span class='object_link'><a href="EnhancedErrors.html#on_format-class_method" title="EnhancedErrors.on_format (method)">on_format</a></span></span> <span class='op'>=</span> <span class='id identifier rubyid_lambda'>lambda</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_formatted_string'>formatted_string</span><span class='op'>|</span>
376
- <span class='id identifier rubyid_encrypted_data'>encrypted_data</span> <span class='op'>=</span> <span class='id identifier rubyid_encryptor'>encryptor</span><span class='period'>.</span><span class='id identifier rubyid_encrypt_and_sign'>encrypt_and_sign</span><span class='lparen'>(</span><span class='id identifier rubyid_formatted_string'>formatted_string</span><span class='rparen'>)</span>
377
- <span class='id identifier rubyid_encrypted_base64'>encrypted_base64</span> <span class='op'>=</span> <span class='const'>Base64</span><span class='period'>.</span><span class='id identifier rubyid_strict_encode64'>strict_encode64</span><span class='lparen'>(</span><span class='id identifier rubyid_encrypted_data'>encrypted_data</span><span class='rparen'>)</span>
378
- <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ENCRYPTED[</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_encrypted_base64'>encrypted_base64</span><span class='embexpr_end'>}</span><span class='tstring_content'>]</span><span class='tstring_end'>&quot;</span></span>
379
- <span class='kw'>end</span>
380
- </code></pre>
381
-
382
371
  <h2 id="label-How+It+Works">How It Works</h2>
383
372
 
384
373
  <p>EnhancedErrors uses Ruby’s <code>TracePoint</code> to listen for <code>:raise</code> and <code>:rescue</code> events. When an exception is raised or rescued, it captures:</p>
@@ -394,7 +383,7 @@
394
383
  <p><strong>Global Variables</strong>: Global variables, in debug mode.</p>
395
384
  </li></ul>
396
385
 
397
- <p>The captured data includes a <code>capture_type</code> field indicating whether the data was captured during a <code>raise</code> or <code>rescue</code> event. By default, EnhancedErrors returns the first <code>raise</code> and the last <code>rescue</code> event for each exception, providing a clear trace of the exception lifecycle.</p>
386
+ <p>The captured data includes a <code>capture_event</code> field indicating whether the data was captured during a <code>raise</code> or <code>rescue</code> event. By default, EnhancedErrors returns the first <code>raise</code> and the last <code>rescue</code> event for each exception, providing a clear trace of the exception lifecycle.</p>
398
387
 
399
388
  <p>The captured data is then appended to the exception’s message, providing rich context for debugging.</p>
400
389
 
@@ -409,7 +398,7 @@
409
398
  <ul><li>
410
399
  <p><strong>Minimal Overhead</strong>: Since TracePoint is only activated during exception raising and rescuing, the performance impact is negligible during normal operation.</p>
411
400
  </li><li>
412
- <p><strong>Production Safe</strong>: The gem is designed to be safe for production use, giving you valuable insights without compromising performance.</p>
401
+ <p><strong>Production Safe</strong>: 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.</p>
413
402
  </li></ul>
414
403
 
415
404
  <h2 id="label-Contributing">Contributing</h2>
@@ -422,7 +411,7 @@
422
411
  </div></div>
423
412
 
424
413
  <div id="footer">
425
- Generated on Tue Oct 22 23:16:25 2024 by
414
+ Generated on Sun Nov 10 12:01:13 2024 by
426
415
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
427
416
  0.9.37 (ruby-3.1.3).
428
417
  </div>
data/doc/index.html CHANGED
@@ -91,37 +91,34 @@
91
91
 
92
92
  <h5 id="label-Output-3A">Output:</h5>
93
93
 
94
- <p>&lt;img src=“./doc/images/enhanced-error.png” style=“height: 171px; width: 440px;”&gt;&lt;/img&gt;</p>
95
-
96
- <p><br></p>
94
+ <p>&lt;img src=“./doc/images/enhanced-error.png” style=“height: 215px; width: 429px;”&gt;&lt;/img&gt; <br></p>
97
95
 
98
96
  <h4 id="label-Enhanced+Exception+In+Specs-3A">Enhanced Exception In Specs:</h4>
99
97
 
100
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_describe'>describe</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>attains enlightenment</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>do</span>
101
- <span class='id identifier rubyid_let'>let</span><span class='lparen'>(</span><span class='symbol'>:the_matrix</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>code rains, dramatically</span><span class='tstring_end'>&#39;</span></span> <span class='rbrace'>}</span>
98
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_describe'>describe</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>sees through</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>do</span>
102
99
 
103
- <span class='id identifier rubyid_before'>before</span><span class='lparen'>(</span><span class='symbol'>:each</span><span class='rparen'>)</span> <span class='kw'>do</span>
104
- <span class='ivar'>@spoon</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>there is no spoon</span><span class='tstring_end'>&#39;</span></span>
105
- <span class='kw'>end</span>
100
+ <span class='id identifier rubyid_let'>let</span><span class='lparen'>(</span><span class='symbol'>:the_matrix</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>code rains, dramatically</span><span class='tstring_end'>&#39;</span></span> <span class='rbrace'>}</span>
106
101
 
107
- <span class='id identifier rubyid_it'>it</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>in the matrix</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>do</span>
108
- <span class='comment'>#activate memoized item
109
- </span> <span class='id identifier rubyid_the_matrix'>the_matrix</span>
110
- <span class='id identifier rubyid_stop'>stop</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>bullets</span><span class='tstring_end'>&#39;</span></span>
111
- <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>No!</span><span class='tstring_end'>&#39;</span></span>
112
- <span class='kw'>end</span>
102
+ <span class='id identifier rubyid_before'>before</span><span class='lparen'>(</span><span class='symbol'>:each</span><span class='rparen'>)</span> <span class='kw'>do</span>
103
+ <span class='ivar'>@spoon</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>there is no spoon</span><span class='tstring_end'>&#39;</span></span>
113
104
  <span class='kw'>end</span>
105
+
106
+ <span class='id identifier rubyid_it'>it</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>the matrix</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>do</span>
107
+ <span class='comment'>#activate memoized item
108
+ </span> <span class='id identifier rubyid_the_matrix'>the_matrix</span>
109
+ <span class='id identifier rubyid_stop'>stop</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>bullets</span><span class='tstring_end'>&#39;</span></span>
110
+ <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>No!</span><span class='tstring_end'>&#39;</span></span>
111
+ <span class='kw'>end</span>
112
+ <span class='kw'>end</span>
114
113
  </code></pre>
115
114
 
116
115
  <h4 id="label-Output-3A">Output:</h4>
117
116
 
118
- <p>&lt;img src=“./doc/images/enhanced-spec.png” style=“height: 426px; width: 712px;”&gt;&lt;/img&gt;</p>
117
+ <p>&lt;img src=“./doc/images/enhanced-spec.png” style=“height: 369px; width: 712px;”&gt;&lt;/img&gt;</p>
119
118
 
120
119
  <h2 id="label-Features">Features</h2>
121
120
  <ul><li>
122
- <p><strong>Pure Ruby</strong>: No external dependencies or C extensions.</p>
123
- </li><li>
124
- <p><strong>Standalone</strong>: Does not rely on any external libraries.</p>
121
+ <p><strong>Pure Ruby</strong>: No external dependencies, C extensions, or C API calls.</p>
125
122
  </li><li>
126
123
  <p><strong>Lightweight</strong>: Minimal performance impact, as tracing is only active during exception raising.</p>
127
124
  </li><li>
@@ -208,6 +205,8 @@
208
205
  <p><code>max_length</code>: Sets the maximum length of the enhanced message (default: <code>2500</code>).</p>
209
206
  </li></ul>
210
207
 
208
+ <p>Currently, the first <code>raise</code> exception binding is presented. This may be changed in the future to allow more binding data to be presented.</p>
209
+
211
210
  <h3 id="label-Environment-Based+Defaults">Environment-Based Defaults</h3>
212
211
 
213
212
  <p>EnhancedErrors adjusts its default settings based on the environment:</p>
@@ -270,7 +269,7 @@
270
269
  globals: globals
271
270
  },
272
271
  exception: exception.class.name,
273
- capture_type: capture_type # &#39;raise&#39; or &#39;rescue&#39;
272
+ capture_event: capture_event # &#39;raise&#39; or &#39;rescue&#39;
274
273
  }
275
274
  </code></pre>
276
275
 
@@ -315,13 +314,32 @@
315
314
 
316
315
  <p>The skip list is pre-populated with common variables to exclude and can be extended based on your application’s requirements.</p>
317
316
 
317
+ <h4 id="label-Capture+Rules">Capture Rules</h4>
318
+
319
+ <p>These exceptions are always ignored:</p>
320
+
321
+ <pre class="code ruby"><code class="ruby">SystemExit,
322
+ NoMemoryError,
323
+ SignalException,
324
+ Interrupt,
325
+ ScriptError,
326
+ LoadError,
327
+ NotImplementedError,
328
+ SyntaxError,
329
+ SystemStackError
330
+ </code></pre>
331
+
332
+ <p>While this is close to “Things that don’t descend from StandardError”, it’s not exactly that.</p>
333
+
334
+ <p>In Info mode, variables starting with @_ are also ignored.</p>
335
+
318
336
  <h3 id="label-Capture+Levels">Capture Levels</h3>
319
337
 
320
338
  <p>EnhancedErrors supports different capture levels to control the verbosity of the captured data:</p>
321
339
  <ul><li>
322
340
  <p><strong>Info Level</strong>: Respects the skip list, excluding predefined sensitive or irrelevant variables. Global variables are ignored.</p>
323
341
  </li><li>
324
- <p><strong>Debug Level</strong>: Ignores the skip lists, capturing all variables including those typically excluded and global variables. Global variables,</p>
342
+ <p><strong>Debug Level</strong>: Ignores the skip lists, capturing all variables including those typically excluded and global variables. Global variables are only captured in debug mode, and they exclude the default Ruby global variables.</p>
325
343
  </li></ul>
326
344
 
327
345
  <p><strong>Default Behavior</strong>: By default, <code>info</code> level is used, which excludes variables in the skip list to protect sensitive information. In <code>debug</code> 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. The info mode is recommended.</p>
@@ -335,7 +353,7 @@
335
353
  <p><strong><code>rescue</code></strong>: Captures the context when an exception is last rescued.</p>
336
354
  </li></ul>
337
355
 
338
- <p><strong>Default Behavior</strong>: By default, EnhancedErrors returns the first <code>raise</code> and the last <code>rescue</code> event for each exception. This provides a clear picture of where and how the exception was handled.</p>
356
+ <p><strong>Default Behavior</strong>: By default, EnhancedErrors returns the first <code>raise</code> and the last <code>rescue</code> event for each exception. The <code>rescue</code> exception is only available in Ruby 3.2+ as it was added to TracePoint events in Ruby 3.2.</p>
339
357
 
340
358
  <h3 id="label-Example-3A+Redacting+Sensitive+Information">Example: Redacting Sensitive Information</h3>
341
359
 
@@ -350,35 +368,6 @@
350
368
  <span class='kw'>end</span>
351
369
  </code></pre>
352
370
 
353
- <h3 id="label-Example-3A+Encrypting+Data+in+Custom+Format">Example: Encrypting Data in Custom Format</h3>
354
-
355
- <pre class="code ruby"><code class="ruby"><span class='comment'># config/initializers/encryption.rb
356
- </span>
357
- <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>active_support</span><span class='tstring_end'>&#39;</span></span>
358
-
359
- <span class='comment'># Retrieve the encryption key from Rails credentials or environment variables
360
- </span><span class='const'>ENCRYPTION_KEY</span> <span class='op'>=</span> <span class='const'>Rails</span><span class='period'>.</span><span class='id identifier rubyid_application'>application</span><span class='period'>.</span><span class='id identifier rubyid_credentials'>credentials</span><span class='period'>.</span><span class='id identifier rubyid_encryption_key'>encryption_key</span> <span class='op'>||</span> <span class='const'>ENV</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ENCRYPTION_KEY</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span>
361
-
362
- <span class='comment'># It&#39;s recommended to use a 256-bit key (32 bytes)
363
- </span><span class='comment'># If your key is in hex or another format, ensure it&#39;s properly decoded
364
- </span><span class='id identifier rubyid_key'>key</span> <span class='op'>=</span> <span class='const'>ActiveSupport</span><span class='op'>::</span><span class='const'>KeyGenerator</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>ENCRYPTION_KEY</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_generate_key'>generate_key</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>enhanced_errors</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='int'>32</span><span class='rparen'>)</span>
365
- <span class='const'>ENCRYPTOR</span> <span class='op'>=</span> <span class='const'>ActiveSupport</span><span class='op'>::</span><span class='const'>MessageEncryptor</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
366
- </code></pre>
367
-
368
- <pre class="code ruby"><code class="ruby">
369
- <span class='id identifier rubyid_require_relative'>require_relative</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>path_to/enhanced_errors</span><span class='tstring_end'>&#39;</span></span> <span class='comment'># Adjust the path accordingly
370
- </span><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>active_support/message_encryptor</span><span class='tstring_end'>&#39;</span></span>
371
-
372
- <span class='comment'># Ensure the encryptor is initialized
373
- </span><span class='id identifier rubyid_encryptor'>encryptor</span> <span class='op'>=</span> <span class='const'>ENCRYPTOR</span>
374
-
375
- <span class='const'><span class='object_link'><a href="EnhancedErrors.html" title="EnhancedErrors (class)">EnhancedErrors</a></span></span><span class='period'>.</span><span class='id identifier rubyid_on_format'><span class='object_link'><a href="EnhancedErrors.html#on_format-class_method" title="EnhancedErrors.on_format (method)">on_format</a></span></span> <span class='op'>=</span> <span class='id identifier rubyid_lambda'>lambda</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_formatted_string'>formatted_string</span><span class='op'>|</span>
376
- <span class='id identifier rubyid_encrypted_data'>encrypted_data</span> <span class='op'>=</span> <span class='id identifier rubyid_encryptor'>encryptor</span><span class='period'>.</span><span class='id identifier rubyid_encrypt_and_sign'>encrypt_and_sign</span><span class='lparen'>(</span><span class='id identifier rubyid_formatted_string'>formatted_string</span><span class='rparen'>)</span>
377
- <span class='id identifier rubyid_encrypted_base64'>encrypted_base64</span> <span class='op'>=</span> <span class='const'>Base64</span><span class='period'>.</span><span class='id identifier rubyid_strict_encode64'>strict_encode64</span><span class='lparen'>(</span><span class='id identifier rubyid_encrypted_data'>encrypted_data</span><span class='rparen'>)</span>
378
- <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ENCRYPTED[</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_encrypted_base64'>encrypted_base64</span><span class='embexpr_end'>}</span><span class='tstring_content'>]</span><span class='tstring_end'>&quot;</span></span>
379
- <span class='kw'>end</span>
380
- </code></pre>
381
-
382
371
  <h2 id="label-How+It+Works">How It Works</h2>
383
372
 
384
373
  <p>EnhancedErrors uses Ruby’s <code>TracePoint</code> to listen for <code>:raise</code> and <code>:rescue</code> events. When an exception is raised or rescued, it captures:</p>
@@ -394,7 +383,7 @@
394
383
  <p><strong>Global Variables</strong>: Global variables, in debug mode.</p>
395
384
  </li></ul>
396
385
 
397
- <p>The captured data includes a <code>capture_type</code> field indicating whether the data was captured during a <code>raise</code> or <code>rescue</code> event. By default, EnhancedErrors returns the first <code>raise</code> and the last <code>rescue</code> event for each exception, providing a clear trace of the exception lifecycle.</p>
386
+ <p>The captured data includes a <code>capture_event</code> field indicating whether the data was captured during a <code>raise</code> or <code>rescue</code> event. By default, EnhancedErrors returns the first <code>raise</code> and the last <code>rescue</code> event for each exception, providing a clear trace of the exception lifecycle.</p>
398
387
 
399
388
  <p>The captured data is then appended to the exception’s message, providing rich context for debugging.</p>
400
389
 
@@ -409,7 +398,7 @@
409
398
  <ul><li>
410
399
  <p><strong>Minimal Overhead</strong>: Since TracePoint is only activated during exception raising and rescuing, the performance impact is negligible during normal operation.</p>
411
400
  </li><li>
412
- <p><strong>Production Safe</strong>: The gem is designed to be safe for production use, giving you valuable insights without compromising performance.</p>
401
+ <p><strong>Production Safe</strong>: 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.</p>
413
402
  </li></ul>
414
403
 
415
404
  <h2 id="label-Contributing">Contributing</h2>
@@ -422,7 +411,7 @@
422
411
  </div></div>
423
412
 
424
413
  <div id="footer">
425
- Generated on Tue Oct 22 23:16:25 2024 by
414
+ Generated on Sun Nov 10 12:01:13 2024 by
426
415
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
427
416
  0.9.37 (ruby-3.1.3).
428
417
  </div>
@@ -91,6 +91,43 @@
91
91
 
92
92
  </p>
93
93
 
94
+
95
+ <h2>
96
+ Constant Summary
97
+ <small><a href="#" class="constants_summary_toggle">collapse</a></small>
98
+ </h2>
99
+
100
+ <dl class="constants">
101
+
102
+ <dt id="IGNORED_EXCEPTIONS-constant" class="">IGNORED_EXCEPTIONS =
103
+ <div class="docstring">
104
+ <div class="discussion">
105
+
106
+ <p>While we could just catch StandardError, we would miss a number of things.</p>
107
+
108
+
109
+ </div>
110
+ </div>
111
+ <div class="tags">
112
+
113
+
114
+ </div>
115
+ </dt>
116
+ <dd><pre class="code"><span class='lbracket'>[</span>
117
+ <span class='const'>SystemExit</span><span class='comma'>,</span>
118
+ <span class='const'>NoMemoryError</span><span class='comma'>,</span>
119
+ <span class='const'>SignalException</span><span class='comma'>,</span>
120
+ <span class='const'>Interrupt</span><span class='comma'>,</span>
121
+ <span class='const'>ScriptError</span><span class='comma'>,</span>
122
+ <span class='const'>LoadError</span><span class='comma'>,</span>
123
+ <span class='const'>NotImplementedError</span><span class='comma'>,</span>
124
+ <span class='const'>SyntaxError</span><span class='comma'>,</span>
125
+ <span class='const'>SystemStackError</span>
126
+ <span class='rbracket'>]</span></pre></dd>
127
+
128
+ </dl>
129
+
130
+
94
131
 
95
132
 
96
133
 
@@ -102,7 +139,7 @@
102
139
  </div>
103
140
 
104
141
  <div id="footer">
105
- Generated on Tue Oct 22 23:16:25 2024 by
142
+ Generated on Sun Nov 10 12:01:14 2024 by
106
143
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
107
144
  0.9.37 (ruby-3.1.3).
108
145
  </div>
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "enhanced_errors"
3
- spec.version = "0.1.4"
3
+ spec.version = "0.1.6"
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."
7
- spec.description = "With no extra dependencies, and using only Ruby's built-in TracePoint, EnhancedErrors will automatically enhance your errors with messages containing variable values from the moment they were raised."
7
+ spec.description = "EnhancedErrors will automatically enhance your errors with messages containing variable values from the moment they were raised, using no extra dependencies, and only Ruby's built-in TracePoint. "
8
8
  spec.homepage = "https://github.com/ericbeland/enhanced_errors"
9
9
  spec.required_ruby_version = ">= 3.0.0"
10
10