enhanced_errors 0.1.4 → 0.1.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: 8fe5b1005d924a2d75afc6603d81b9a858b44158a94f97e71381ee12f0d9f691
4
- data.tar.gz: 8a574198151511f3b7774d95fb06217ba6739a258d8092724bd1fc2238071634
3
+ metadata.gz: 62b2a3fc44ab649a8a20dafe2f144b73047a1d1cd63f9ed539d79b3ce912cf93
4
+ data.tar.gz: 7b1af394f468c3ab240f20b61b4275384b2e1b16ffdd9296d7f0480cefcd17d1
5
5
  SHA512:
6
- metadata.gz: 5b6674b41ae75c55c5433ebd58cb3a214198183345993931f2a88e6df0eb58b2c0908ea1103c6c296a7899fb554570c65ec72d19c58377ef611718423810b83e
7
- data.tar.gz: 5885b07b737a9758ec18bca9f55a7d0b305cb0b5300decd0250999dc08a2d470dcb014085db913af6fafab3b8b64e1e30dd8d6f54a5681dda491fee27fd3fb88
6
+ metadata.gz: a290300d7c90b09b6551daff97c945ba6b5f523760fee3950c6e7cf45665ba61665619156a32a5841861f1405a1454dbf1bcae8e07de7bc0a26b71d3b7f3a7bf
7
+ data.tar.gz: 4e3156d2e01bef30ce0a4c467382625eae7a93b4cb3b4ed8cfc103c7dd112514eb0865ad42bead9b068248682e19d5c7c43143e5495036937824860d9a004a7f
data/.yardoc/checksums CHANGED
@@ -1,4 +1,4 @@
1
1
  lib/colors.rb a4314ef9531d4713907c3fea22955c943fdb8cf3
2
2
  lib/binding.rb fdd7d5a2dd2edde22e3b10773510738dcdce4aeb
3
- lib/enhanced_errors.rb 314e2109290db51b63e2e417f67b834425131726
4
- lib/error_enhancements.rb 5ff3b60d76a44979b9745d1c47e77f7569fd03ac
3
+ lib/enhanced_errors.rb 5c7cd4a2a693b60bd34a0952e411db3578a1e72f
4
+ lib/error_enhancements.rb d173fd391911b83485277f5c4a8b80c4e1178d36
data/.yardoc/object_types CHANGED
Binary file
Binary file
data/README.md CHANGED
@@ -202,7 +202,7 @@ it yields out a hash with the structure below. Modify it as needed and return th
202
202
  globals: globals
203
203
  },
204
204
  exception: exception.class.name,
205
- capture_type: capture_type # 'raise' or 'rescue'
205
+ capture_event: capture_event # 'raise' or 'rescue'
206
206
  }
207
207
  ```
208
208
 
@@ -316,7 +316,7 @@ When an exception is raised or rescued, it captures:
316
316
  - **Let Variables**: RSpec let variables, if applicable. Only memoized (evaluated) let variables are captured.
317
317
  - **Global Variables**: Global variables, in debug mode.
318
318
 
319
- The captured data includes a `capture_type` field indicating whether the data was captured during a `raise` or `rescue` event. By default, EnhancedErrors returns the first `raise` and the last `rescue` event for each exception, providing a clear trace of the exception lifecycle.
319
+ The captured data includes a `capture_event` field indicating whether the data was captured during a `raise` or `rescue` event. By default, EnhancedErrors returns the first `raise` and the last `rescue` event for each exception, providing a clear trace of the exception lifecycle.
320
320
 
321
321
  The captured data is then appended to the exception's message, providing rich context for debugging.
322
322
 
data/doc/Binding.html CHANGED
@@ -127,7 +127,7 @@
127
127
  </div>
128
128
 
129
129
  <div id="footer">
130
- Generated on Tue Oct 22 23:16:25 2024 by
130
+ Generated on Fri Oct 25 11:07:02 2024 by
131
131
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
132
132
  0.9.37 (ruby-3.1.3).
133
133
  </div>
data/doc/Colors.html CHANGED
@@ -374,7 +374,7 @@
374
374
  </div>
375
375
 
376
376
  <div id="footer">
377
- Generated on Tue Oct 22 23:16:25 2024 by
377
+ Generated on Fri Oct 25 11:07:02 2024 by
378
378
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
379
379
  0.9.37 (ruby-3.1.3).
380
380
  </div>
data/doc/Debugging.html CHANGED
@@ -171,7 +171,7 @@
171
171
  </div>
172
172
 
173
173
  <div id="footer">
174
- Generated on Tue Oct 22 23:16:25 2024 by
174
+ Generated on Fri Oct 25 11:07:02 2024 by
175
175
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
176
176
  0.9.37 (ruby-3.1.3).
177
177
  </div>
@@ -618,7 +618,7 @@
618
618
  <li class="public ">
619
619
  <span class="summary_signature">
620
620
 
621
- <a href="#enhance!-class_method" title="enhance! (class method)">.<strong>enhance!</strong>(enabled: true, debug: false, **options) {|void| ... } &#x21d2; void </a>
621
+ <a href="#enhance!-class_method" title="enhance! (class method)">.<strong>enhance!</strong>(enabled: true, debug: false, capture_events: default_capture_events, **options) {|void| ... } &#x21d2; void </a>
622
622
 
623
623
 
624
624
 
@@ -1520,18 +1520,18 @@
1520
1520
  <pre class="lines">
1521
1521
 
1522
1522
 
1523
- 311
1524
- 312
1525
1523
  313
1526
1524
  314
1527
1525
  315
1528
1526
  316
1529
1527
  317
1530
1528
  318
1531
- 319</pre>
1529
+ 319
1530
+ 320
1531
+ 321</pre>
1532
1532
  </td>
1533
1533
  <td>
1534
- <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 311</span>
1534
+ <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 313</span>
1535
1535
 
1536
1536
  <span class='kw'>def</span> <span class='id identifier rubyid_apply_skip_list'>apply_skip_list</span><span class='lparen'>(</span><span class='id identifier rubyid_binding_info'>binding_info</span><span class='rparen'>)</span>
1537
1537
  <span class='kw'>unless</span> <span class='ivar'>@debug</span>
@@ -1611,8 +1611,6 @@
1611
1611
  <pre class="lines">
1612
1612
 
1613
1613
 
1614
- 337
1615
- 338
1616
1614
  339
1617
1615
  340
1618
1616
  341
@@ -1641,13 +1639,17 @@
1641
1639
  364
1642
1640
  365
1643
1641
  366
1644
- 367</pre>
1642
+ 367
1643
+ 368
1644
+ 369
1645
+ 370</pre>
1645
1646
  </td>
1646
1647
  <td>
1647
- <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 337</span>
1648
+ <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 339</span>
1648
1649
 
1649
1650
  <span class='kw'>def</span> <span class='id identifier rubyid_binding_info_string'>binding_info_string</span><span class='lparen'>(</span><span class='id identifier rubyid_binding_info'>binding_info</span><span class='rparen'>)</span>
1650
- <span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\n</span><span class='embexpr_beg'>#{</span><span class='const'><span class='object_link'><a href="Colors.html" title="Colors (class)">Colors</a></span></span><span class='period'>.</span><span class='id identifier rubyid_green'>green</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_binding_info'>binding_info</span><span class='lbracket'>[</span><span class='symbol'>:capture_type</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_capitalize'>capitalize</span><span class='embexpr_end'>}</span><span class='tstring_content'>: </span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='embexpr_beg'>#{</span><span class='const'><span class='object_link'><a href="Colors.html" title="Colors (class)">Colors</a></span></span><span class='period'>.</span><span class='id identifier rubyid_blue'>blue</span><span class='lparen'>(</span><span class='id identifier rubyid_binding_info'>binding_info</span><span class='lbracket'>[</span><span class='symbol'>:source</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
1651
+ <span class='id identifier rubyid_capture_event'>capture_event</span> <span class='op'>=</span> <span class='id identifier rubyid_binding_info'>binding_info</span><span class='lbracket'>[</span><span class='symbol'>:capture_event</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_capitalize'>capitalize</span>
1652
+ <span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='const'><span class='object_link'><a href="Colors.html" title="Colors (class)">Colors</a></span></span><span class='period'>.</span><span class='id identifier rubyid_red'>red</span><span class='lparen'>(</span><span class='id identifier rubyid_capture_event'>capture_event</span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_content'>: </span><span class='embexpr_beg'>#{</span><span class='const'><span class='object_link'><a href="Colors.html" title="Colors (class)">Colors</a></span></span><span class='period'>.</span><span class='id identifier rubyid_blue'>blue</span><span class='lparen'>(</span><span class='id identifier rubyid_binding_info'>binding_info</span><span class='lbracket'>[</span><span class='symbol'>:source</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
1651
1653
 
1652
1654
  <span class='id identifier rubyid_result'>result</span> <span class='op'>+=</span> <span class='id identifier rubyid_method_and_args_desc'>method_and_args_desc</span><span class='lparen'>(</span><span class='id identifier rubyid_binding_info'>binding_info</span><span class='lbracket'>[</span><span class='symbol'>:method_and_args</span><span class='rbracket'>]</span><span class='rparen'>)</span>
1653
1655
 
@@ -1675,7 +1677,7 @@
1675
1677
  <span class='kw'>if</span> <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>&gt;</span> <span class='id identifier rubyid_max_length'>max_length</span>
1676
1678
  <span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='id identifier rubyid_result'>result</span><span class='lbracket'>[</span><span class='int'>0</span><span class='op'>...</span><span class='id identifier rubyid_max_length'>max_length</span><span class='rbracket'>]</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>... (truncated)</span><span class='tstring_end'>&quot;</span></span>
1677
1679
  <span class='kw'>end</span>
1678
- <span class='id identifier rubyid_result'>result</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\n\n</span><span class='tstring_end'>&quot;</span></span>
1680
+ <span class='id identifier rubyid_result'>result</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\n</span><span class='tstring_end'>&quot;</span></span>
1679
1681
  <span class='kw'>end</span></pre>
1680
1682
  </td>
1681
1683
  </tr>
@@ -1764,8 +1766,6 @@
1764
1766
  <pre class="lines">
1765
1767
 
1766
1768
 
1767
- 253
1768
- 254
1769
1769
  255
1770
1770
  256
1771
1771
  257
@@ -1779,10 +1779,12 @@
1779
1779
  265
1780
1780
  266
1781
1781
  267
1782
- 268</pre>
1782
+ 268
1783
+ 269
1784
+ 270</pre>
1783
1785
  </td>
1784
1786
  <td>
1785
- <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 253</span>
1787
+ <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 255</span>
1786
1788
 
1787
1789
  <span class='kw'>def</span> <span class='id identifier rubyid_binding_infos_array_to_string'>binding_infos_array_to_string</span><span class='lparen'>(</span><span class='id identifier rubyid_captured_bindings'>captured_bindings</span><span class='comma'>,</span> <span class='id identifier rubyid_format'>format</span> <span class='op'>=</span> <span class='symbol'>:terminal</span><span class='rparen'>)</span>
1788
1790
  <span class='kw'>case</span> <span class='id identifier rubyid_format'>format</span>
@@ -1867,7 +1869,7 @@
1867
1869
  <div class="method_details ">
1868
1870
  <h3 class="signature " id="enhance!-class_method">
1869
1871
 
1870
- .<strong>enhance!</strong>(enabled: true, debug: false, **options) {|void| ... } &#x21d2; <tt>void</tt>
1872
+ .<strong>enhance!</strong>(enabled: true, debug: false, capture_events: default_capture_events, **options) {|void| ... } &#x21d2; <tt>void</tt>
1871
1873
 
1872
1874
 
1873
1875
 
@@ -1993,12 +1995,15 @@
1993
1995
  176
1994
1996
  177
1995
1997
  178
1996
- 179</pre>
1998
+ 179
1999
+ 180
2000
+ 181</pre>
1997
2001
  </td>
1998
2002
  <td>
1999
2003
  <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 150</span>
2000
2004
 
2001
- <span class='kw'>def</span> <span class='id identifier rubyid_enhance!'>enhance!</span><span class='lparen'>(</span><span class='label'>enabled:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>debug:</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
2005
+ <span class='kw'>def</span> <span class='id identifier rubyid_enhance!'>enhance!</span><span class='lparen'>(</span><span class='label'>enabled:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>debug:</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='label'>capture_events:</span> <span class='id identifier rubyid_default_capture_events'>default_capture_events</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
2006
+ <span class='id identifier rubyid_capture_events'>capture_events</span> <span class='op'>=</span> <span class='const'>Array</span><span class='lparen'>(</span><span class='id identifier rubyid_capture_events'>capture_events</span><span class='rparen'>)</span>
2002
2007
  <span class='ivar'>@output_format</span> <span class='op'>=</span> <span class='kw'>nil</span>
2003
2008
  <span class='ivar'>@eligible_for_capture</span> <span class='op'>=</span> <span class='kw'>nil</span>
2004
2009
  <span class='ivar'>@original_global_variables</span> <span class='op'>=</span> <span class='kw'>nil</span>
@@ -2011,6 +2016,7 @@
2011
2016
  <span class='ivar'>@debug</span> <span class='op'>=</span> <span class='id identifier rubyid_debug'>debug</span>
2012
2017
  <span class='ivar'>@original_global_variables</span> <span class='op'>=</span> <span class='id identifier rubyid_global_variables'>global_variables</span>
2013
2018
 
2019
+ <span class='id identifier rubyid_validate_and_set_capture_events'>validate_and_set_capture_events</span><span class='lparen'>(</span><span class='id identifier rubyid_capture_events'>capture_events</span><span class='rparen'>)</span>
2014
2020
  <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='op'>|</span>
2015
2021
  <span class='id identifier rubyid_setter_method'>setter_method</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>=</span><span class='tstring_end'>&quot;</span></span>
2016
2022
  <span class='kw'>if</span> <span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='id identifier rubyid_setter_method'>setter_method</span><span class='rparen'>)</span>
@@ -2117,18 +2123,18 @@
2117
2123
  <pre class="lines">
2118
2124
 
2119
2125
 
2120
- 238
2121
- 239
2122
2126
  240
2123
2127
  241
2124
2128
  242
2125
2129
  243
2126
2130
  244
2127
2131
  245
2128
- 246</pre>
2132
+ 246
2133
+ 247
2134
+ 248</pre>
2129
2135
  </td>
2130
2136
  <td>
2131
- <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 238</span>
2137
+ <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 240</span>
2132
2138
 
2133
2139
  <span class='kw'>def</span> <span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='id identifier rubyid_captured_bindings'>captured_bindings</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_output_format'>output_format</span> <span class='op'>=</span> <span class='id identifier rubyid_get_default_format_for_environment'>get_default_format_for_environment</span><span class='rparen'>)</span>
2134
2140
  <span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='id identifier rubyid_binding_infos_array_to_string'>binding_infos_array_to_string</span><span class='lparen'>(</span><span class='id identifier rubyid_captured_bindings'>captured_bindings</span><span class='comma'>,</span> <span class='id identifier rubyid_output_format'>output_format</span><span class='rparen'>)</span>
@@ -2188,8 +2194,6 @@
2188
2194
  <pre class="lines">
2189
2195
 
2190
2196
 
2191
- 273
2192
- 274
2193
2197
  275
2194
2198
  276
2195
2199
  277
@@ -2203,10 +2207,12 @@
2203
2207
  285
2204
2208
  286
2205
2209
  287
2206
- 288</pre>
2210
+ 288
2211
+ 289
2212
+ 290</pre>
2207
2213
  </td>
2208
2214
  <td>
2209
- <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 273</span>
2215
+ <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 275</span>
2210
2216
 
2211
2217
  <span class='kw'>def</span> <span class='id identifier rubyid_get_default_format_for_environment'>get_default_format_for_environment</span>
2212
2218
  <span class='kw'>return</span> <span class='ivar'>@output_format</span> <span class='kw'>unless</span> <span class='ivar'>@output_format</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
@@ -2293,16 +2299,16 @@
2293
2299
  <pre class="lines">
2294
2300
 
2295
2301
 
2296
- 197
2297
- 198
2298
2302
  199
2299
2303
  200
2300
2304
  201
2301
2305
  202
2302
- 203</pre>
2306
+ 203
2307
+ 204
2308
+ 205</pre>
2303
2309
  </td>
2304
2310
  <td>
2305
- <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 197</span>
2311
+ <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 199</span>
2306
2312
 
2307
2313
  <span class='kw'>def</span> <span class='id identifier rubyid_on_capture'>on_capture</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
2308
2314
  <span class='kw'>if</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
@@ -2380,12 +2386,12 @@
2380
2386
  <pre class="lines">
2381
2387
 
2382
2388
 
2383
- 209
2384
- 210
2385
- 211</pre>
2389
+ 211
2390
+ 212
2391
+ 213</pre>
2386
2392
  </td>
2387
2393
  <td>
2388
- <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 209</span>
2394
+ <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 211</span>
2389
2395
 
2390
2396
  <span class='kw'>def</span> <span class='id identifier rubyid_on_capture='>on_capture=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
2391
2397
  <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_on_capture_hook'>on_capture_hook</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span>
@@ -2459,16 +2465,16 @@
2459
2465
  <pre class="lines">
2460
2466
 
2461
2467
 
2462
- 217
2463
- 218
2464
2468
  219
2465
2469
  220
2466
2470
  221
2467
2471
  222
2468
- 223</pre>
2472
+ 223
2473
+ 224
2474
+ 225</pre>
2469
2475
  </td>
2470
2476
  <td>
2471
- <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 217</span>
2477
+ <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 219</span>
2472
2478
 
2473
2479
  <span class='kw'>def</span> <span class='id identifier rubyid_on_format'>on_format</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
2474
2480
  <span class='kw'>if</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
@@ -2546,12 +2552,12 @@
2546
2552
  <pre class="lines">
2547
2553
 
2548
2554
 
2549
- 229
2550
- 230
2551
- 231</pre>
2555
+ 231
2556
+ 232
2557
+ 233</pre>
2552
2558
  </td>
2553
2559
  <td>
2554
- <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 229</span>
2560
+ <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 231</span>
2555
2561
 
2556
2562
  <span class='kw'>def</span> <span class='id identifier rubyid_on_format='>on_format=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
2557
2563
  <span class='ivar'>@on_format_hook</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span>
@@ -2605,8 +2611,6 @@
2605
2611
  <pre class="lines">
2606
2612
 
2607
2613
 
2608
- 293
2609
- 294
2610
2614
  295
2611
2615
  296
2612
2616
  297
@@ -2617,10 +2621,12 @@
2617
2621
  302
2618
2622
  303
2619
2623
  304
2620
- 305</pre>
2624
+ 305
2625
+ 306
2626
+ 307</pre>
2621
2627
  </td>
2622
2628
  <td>
2623
- <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 293</span>
2629
+ <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 295</span>
2624
2630
 
2625
2631
  <span class='kw'>def</span> <span class='id identifier rubyid_running_in_ci?'>running_in_ci?</span>
2626
2632
  <span class='kw'>return</span> <span class='ivar'>@running_in_ci</span> <span class='kw'>if</span> <span class='kw'>defined?</span><span class='lparen'>(</span><span class='ivar'>@running_in_ci</span><span class='rparen'>)</span>
@@ -2704,19 +2710,19 @@
2704
2710
  <pre class="lines">
2705
2711
 
2706
2712
 
2707
- 325
2708
- 326
2709
2713
  327
2710
2714
  328
2711
2715
  329
2712
2716
  330
2713
- 331</pre>
2717
+ 331
2718
+ 332
2719
+ 333</pre>
2714
2720
  </td>
2715
2721
  <td>
2716
- <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 325</span>
2722
+ <pre class="code"><span class="info file"># File 'lib/enhanced_errors.rb', line 327</span>
2717
2723
 
2718
2724
  <span class='kw'>def</span> <span class='id identifier rubyid_validate_binding_format'>validate_binding_format</span><span class='lparen'>(</span><span class='id identifier rubyid_binding_info'>binding_info</span><span class='rparen'>)</span>
2719
- <span class='kw'>unless</span> <span class='id identifier rubyid_binding_info'>binding_info</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:capture_type</span><span class='rparen'>)</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_binding_info'>binding_info</span><span class='lbracket'>[</span><span class='symbol'>:variables</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
2725
+ <span class='kw'>unless</span> <span class='id identifier rubyid_binding_info'>binding_info</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:capture_event</span><span class='rparen'>)</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_binding_info'>binding_info</span><span class='lbracket'>[</span><span class='symbol'>:variables</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Hash</span><span class='rparen'>)</span>
2720
2726
  <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Invalid binding_info format.</span><span class='tstring_end'>&quot;</span></span>
2721
2727
  <span class='kw'>return</span> <span class='kw'>nil</span>
2722
2728
  <span class='kw'>end</span>
@@ -2732,7 +2738,7 @@
2732
2738
  </div>
2733
2739
 
2734
2740
  <div id="footer">
2735
- Generated on Tue Oct 22 23:16:25 2024 by
2741
+ Generated on Fri Oct 25 11:07:02 2024 by
2736
2742
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
2737
2743
  0.9.37 (ruby-3.1.3).
2738
2744
  </div>
@@ -179,7 +179,7 @@
179
179
 
180
180
  <span class='kw'>def</span> <span class='id identifier rubyid_message'>message</span>
181
181
  <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>
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='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>
183
183
  <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
184
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
185
  <span class='id identifier rubyid_original_message'>original_message</span>
@@ -242,7 +242,7 @@
242
242
  </div>
243
243
 
244
244
  <div id="footer">
245
- Generated on Tue Oct 22 23:16:25 2024 by
245
+ Generated on Fri Oct 25 11:07:02 2024 by
246
246
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
247
247
  0.9.37 (ruby-3.1.3).
248
248
  </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 Fri Oct 25 11:07:01 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>
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>
113
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
 
@@ -321,7 +320,7 @@
321
320
  <ul><li>
322
321
  <p><strong>Info Level</strong>: Respects the skip list, excluding predefined sensitive or irrelevant variables. Global variables are ignored.</p>
323
322
  </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>
323
+ <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
324
  </li></ul>
326
325
 
327
326
  <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 +334,7 @@
335
334
  <p><strong><code>rescue</code></strong>: Captures the context when an exception is last rescued.</p>
336
335
  </li></ul>
337
336
 
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>
337
+ <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
338
 
340
339
  <h3 id="label-Example-3A+Redacting+Sensitive+Information">Example: Redacting Sensitive Information</h3>
341
340
 
@@ -350,35 +349,6 @@
350
349
  <span class='kw'>end</span>
351
350
  </code></pre>
352
351
 
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
352
  <h2 id="label-How+It+Works">How It Works</h2>
383
353
 
384
354
  <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 +364,7 @@
394
364
  <p><strong>Global Variables</strong>: Global variables, in debug mode.</p>
395
365
  </li></ul>
396
366
 
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>
367
+ <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
368
 
399
369
  <p>The captured data is then appended to the exception’s message, providing rich context for debugging.</p>
400
370
 
@@ -409,7 +379,7 @@
409
379
  <ul><li>
410
380
  <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
381
  </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>
382
+ <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
383
  </li></ul>
414
384
 
415
385
  <h2 id="label-Contributing">Contributing</h2>
@@ -422,7 +392,7 @@
422
392
  </div></div>
423
393
 
424
394
  <div id="footer">
425
- Generated on Tue Oct 22 23:16:25 2024 by
395
+ Generated on Fri Oct 25 11:07:02 2024 by
426
396
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
427
397
  0.9.37 (ruby-3.1.3).
428
398
  </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>
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>
113
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
 
@@ -321,7 +320,7 @@
321
320
  <ul><li>
322
321
  <p><strong>Info Level</strong>: Respects the skip list, excluding predefined sensitive or irrelevant variables. Global variables are ignored.</p>
323
322
  </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>
323
+ <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
324
  </li></ul>
326
325
 
327
326
  <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 +334,7 @@
335
334
  <p><strong><code>rescue</code></strong>: Captures the context when an exception is last rescued.</p>
336
335
  </li></ul>
337
336
 
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>
337
+ <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
338
 
340
339
  <h3 id="label-Example-3A+Redacting+Sensitive+Information">Example: Redacting Sensitive Information</h3>
341
340
 
@@ -350,35 +349,6 @@
350
349
  <span class='kw'>end</span>
351
350
  </code></pre>
352
351
 
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
352
  <h2 id="label-How+It+Works">How It Works</h2>
383
353
 
384
354
  <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 +364,7 @@
394
364
  <p><strong>Global Variables</strong>: Global variables, in debug mode.</p>
395
365
  </li></ul>
396
366
 
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>
367
+ <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
368
 
399
369
  <p>The captured data is then appended to the exception’s message, providing rich context for debugging.</p>
400
370
 
@@ -409,7 +379,7 @@
409
379
  <ul><li>
410
380
  <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
381
  </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>
382
+ <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
383
  </li></ul>
414
384
 
415
385
  <h2 id="label-Contributing">Contributing</h2>
@@ -422,7 +392,7 @@
422
392
  </div></div>
423
393
 
424
394
  <div id="footer">
425
- Generated on Tue Oct 22 23:16:25 2024 by
395
+ Generated on Fri Oct 25 11:07:02 2024 by
426
396
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
427
397
  0.9.37 (ruby-3.1.3).
428
398
  </div>
@@ -102,7 +102,7 @@
102
102
  </div>
103
103
 
104
104
  <div id="footer">
105
- Generated on Tue Oct 22 23:16:25 2024 by
105
+ Generated on Fri Oct 25 11:07:02 2024 by
106
106
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
107
107
  0.9.37 (ruby-3.1.3).
108
108
  </div>
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "enhanced_errors"
3
- spec.version = "0.1.4"
3
+ spec.version = "0.1.5"
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."
@@ -147,7 +147,8 @@ class EnhancedErrors
147
147
  # @param options [Hash] Additional configuration options.
148
148
  # @yield [void] A block for additional configuration.
149
149
  # @return [void]
150
- def enhance!(enabled: true, debug: false, **options, &block)
150
+ def enhance!(enabled: true, debug: false, capture_events: default_capture_events, **options, &block)
151
+ capture_events = Array(capture_events)
151
152
  @output_format = nil
152
153
  @eligible_for_capture = nil
153
154
  @original_global_variables = nil
@@ -160,6 +161,7 @@ class EnhancedErrors
160
161
  @debug = debug
161
162
  @original_global_variables = global_variables
162
163
 
164
+ validate_and_set_capture_events(capture_events)
163
165
  options.each do |key, value|
164
166
  setter_method = "#{key}="
165
167
  if respond_to?(setter_method)
@@ -323,7 +325,7 @@ class EnhancedErrors
323
325
  # @param binding_info [Hash] The binding information to validate.
324
326
  # @return [Hash, nil] The validated binding information or `nil` if invalid.
325
327
  def validate_binding_format(binding_info)
326
- unless binding_info.keys.include?(:capture_type) && binding_info[:variables].is_a?(Hash)
328
+ unless binding_info.keys.include?(:capture_event) && binding_info[:variables].is_a?(Hash)
327
329
  puts "Invalid binding_info format."
328
330
  return nil
329
331
  end
@@ -335,8 +337,8 @@ class EnhancedErrors
335
337
  # @param binding_info [Hash] The binding information to format.
336
338
  # @return [String] The formatted string.
337
339
  def binding_info_string(binding_info)
338
- capture_type = binding_info[:capture_type].to_s.capitalize
339
- result = "#{Colors.red(capture_type)}: #{Colors.blue(binding_info[:source])}"
340
+ capture_event = binding_info[:capture_event].to_s.capitalize
341
+ result = "#{Colors.red(capture_event)}: #{Colors.blue(binding_info[:source])}"
340
342
 
341
343
  result += method_and_args_desc(binding_info[:method_and_args])
342
344
 
@@ -375,8 +377,7 @@ class EnhancedErrors
375
377
  def start_tracing
376
378
  return if @trace && @trace.enabled?
377
379
 
378
- events = [:raise]
379
- events << :rescue if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3.0')
380
+ events = @capture_events ? @capture_events.to_a : [:raise]
380
381
 
381
382
  @trace = TracePoint.new(*events) do |tp|
382
383
  next if Thread.current[:enhanced_errors_processing] || tp.raised_exception.is_a?(NoMemoryError)
@@ -425,10 +426,9 @@ class EnhancedErrors
425
426
  globals = (global_variables - @original_global_variables).map { |var|
426
427
  [var, get_global_variable_value(var)]
427
428
  }.to_h
428
- puts "Global Variables: #{globals.inspect}"
429
429
  end
430
430
 
431
- capture_type = tp.event.to_s # 'raise' or 'rescue'
431
+ capture_event = tp.event.to_s # 'raise' or 'rescue'
432
432
  location = "#{tp.path}:#{tp.lineno}"
433
433
 
434
434
  binding_info = {
@@ -444,7 +444,7 @@ class EnhancedErrors
444
444
  globals: globals
445
445
  },
446
446
  exception: exception.class.name,
447
- capture_type: capture_type.to_s
447
+ capture_event: capture_event.to_s
448
448
  }
449
449
 
450
450
  if on_capture_hook
@@ -469,6 +469,7 @@ class EnhancedErrors
469
469
  @trace.enable
470
470
  end
471
471
 
472
+
472
473
  # Retrieves the current test name from RSpec, if available.
473
474
  #
474
475
  # @return [String, nil] The current test name or `nil` if not in a test context.
@@ -480,6 +481,42 @@ class EnhancedErrors
480
481
  nil
481
482
  end
482
483
 
484
+ # Helper method to determine the default capture types based on Ruby version
485
+ #
486
+ # @return [Set<Symbol>] The default set of capture types
487
+ def default_capture_events
488
+ default_events = [:raise]
489
+ default_events << :rescue if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3.0')
490
+ Set.new(default_events)
491
+ end
492
+
493
+ def validate_and_set_capture_events(capture_events)
494
+ if capture_events.nil? || !valid_capture_events?(capture_events)
495
+ puts "EnhancedErrors: Invalid capture_events provided. Falling back to defaults."
496
+ capture_events = default_capture_events
497
+ end
498
+
499
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.3.0') && capture_events.include?(:rescue)
500
+ puts "EnhancedErrors: Warning: :rescue capture_event is not supported in Ruby versions below 3.3.0 and will be ignored."
501
+ capture_events.delete(:rescue)
502
+ end
503
+
504
+ if capture_events.empty?
505
+ puts "No valid capture_events provided to EnhancedErrors.enhance! Falling back to defaults."
506
+ capture_events = default_capture_events
507
+ end
508
+
509
+ @capture_events = capture_events.to_a
510
+ end
511
+
512
+
513
+ # Validate capture_events: must be an Array or Set containing only :raise and/or :rescue.
514
+ def valid_capture_events?(capture_events)
515
+ return false unless capture_events.is_a?(Array) || capture_events.is_a?(Set)
516
+ valid_types = [:raise, :rescue].to_set
517
+ capture_events.to_set.subset?(valid_types)
518
+ end
519
+
483
520
  # Extracts method arguments from the TracePoint binding.
484
521
  #
485
522
  # @param tp [TracePoint] The current TracePoint.
@@ -31,7 +31,7 @@ module ErrorEnhancements
31
31
  bindings_of_interest = []
32
32
 
33
33
  binding_infos.each do |info|
34
- if info[:capture_type] == 'raise' && !info[:library]
34
+ if info[:capture_event] == 'raise' && !info[:library]
35
35
  bindings_of_interest << info
36
36
  break
37
37
  end
@@ -43,7 +43,7 @@ module ErrorEnhancements
43
43
 
44
44
  # find the last rescue binding if there is one
45
45
  binding_infos.reverse.each do |info|
46
- if info[:capture_type] == 'rescue'
46
+ if info[:capture_event] == 'rescue'
47
47
  bindings_of_interest << info
48
48
  break
49
49
  end
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
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Beland