enhanced_errors 2.0.6 → 2.1.1
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 +4 -4
- data/.yardoc/checksums +4 -4
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/README.md +99 -96
- data/doc/Enhanced/Colors.html +24 -17
- data/doc/Enhanced.html +2 -6
- data/doc/EnhancedErrors.html +1764 -888
- data/doc/Exception.html +1 -1
- data/doc/Minitest.html +238 -0
- data/doc/_index.html +4 -21
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +74 -78
- data/doc/images/enhance.png +0 -0
- data/doc/images/enhanced-error.png +0 -0
- data/doc/images/enhanced-spec.png +0 -0
- data/doc/index.html +74 -78
- data/doc/method_list.html +125 -13
- data/doc/top-level-namespace.html +2 -2
- data/enhanced_errors.gemspec +4 -1
- data/examples/{division_by_zero_example.rb → demo_exception_enhancement.rb} +3 -1
- data/examples/demo_minitest.rb +22 -0
- data/examples/demo_rspec.rb +56 -0
- data/lib/enhanced/minitest_patch.rb +17 -0
- data/lib/enhanced_errors.rb +408 -226
- metadata +24 -5
- data/examples/demo_spec.rb +0 -32
- data/examples/example_spec.rb +0 -47
data/doc/index.html
CHANGED
@@ -62,41 +62,13 @@
|
|
62
62
|
|
63
63
|
<h2 id="label-Overview">Overview</h2>
|
64
64
|
|
65
|
-
<p><strong>EnhancedErrors</strong> is a
|
65
|
+
<p><strong>EnhancedErrors</strong> is a lightweight Ruby gem that enhances exceptions by capturing variables and their values from the scope where the exception was raised.</p>
|
66
66
|
|
67
67
|
<p><strong>EnhancedErrors</strong> leverages Ruby’s built-in <a href="https://ruby-doc.org/core-3.1.0/TracePoint.html">TracePoint</a> feature to provide detailed context for exceptions, making debugging easier without significant performance overhead.</p>
|
68
68
|
|
69
|
-
<p>
|
69
|
+
<p>EnhancedErrors captures exception context using either a test-framework integration (RSpec/Minitest) or a global enhancement for runtime exceptions.</p>
|
70
70
|
|
71
|
-
<
|
72
|
-
|
73
|
-
<pre class="code ruby"><code class="ruby">
|
74
|
-
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>enhanced_errors</span><span class='tstring_end'>'</span></span>
|
75
|
-
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>awesome_print</span><span class='tstring_end'>'</span></span> <span class='comment'># Optional, for better output
|
76
|
-
</span>
|
77
|
-
<span class='comment'># Enable capturing of variables at exception at raise-time. The .captured_variables method
|
78
|
-
</span><span class='comment'># is added to all Exceptions and gets populated with in-scope variables and values on `raise`
|
79
|
-
</span>
|
80
|
-
<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_enhance_exceptions!'><span class='object_link'><a href="EnhancedErrors.html#enhance_exceptions!-class_method" title="EnhancedErrors.enhance_exceptions! (method)">enhance_exceptions!</a></span></span>
|
81
|
-
|
82
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_foo'>foo</span>
|
83
|
-
<span class='kw'>begin</span>
|
84
|
-
<span class='id identifier rubyid_myvar'>myvar</span> <span class='op'>=</span> <span class='int'>0</span>
|
85
|
-
<span class='ivar'>@myinstance</span> <span class='op'>=</span> <span class='int'>10</span>
|
86
|
-
<span class='id identifier rubyid_foo'>foo</span> <span class='op'>=</span> <span class='ivar'>@myinstance</span> <span class='op'>/</span> <span class='id identifier rubyid_myvar'>myvar</span>
|
87
|
-
<span class='kw'>rescue</span> <span class='op'>=></span> <span class='id identifier rubyid_e'>e</span>
|
88
|
-
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_captured_variables'>captured_variables</span>
|
89
|
-
<span class='kw'>end</span>
|
90
|
-
<span class='kw'>end</span>
|
91
|
-
|
92
|
-
<span class='id identifier rubyid_foo'>foo</span>
|
93
|
-
</code></pre>
|
94
|
-
|
95
|
-
<h5 id="label-Output-3A">Output:</h5>
|
96
|
-
|
97
|
-
<p><img src=“./doc/images/enhanced-error.png” style=“height: 215px; width: 429px;”></img> <br></p>
|
98
|
-
|
99
|
-
<h4 id="label-Enhanced+Exception+In+Specs-3A">Enhanced Exception In Specs:</h4>
|
71
|
+
<h3 id="label-Enhanced+Errors+In+RSpec-3A">Enhanced Errors In RSpec:</h3>
|
100
72
|
|
101
73
|
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_describe'>describe</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>sees through</span><span class='tstring_end'>'</span></span> <span class='kw'>do</span>
|
102
74
|
|
@@ -119,50 +91,84 @@
|
|
119
91
|
|
120
92
|
<p><img src=“./doc/images/enhanced-spec.png” style=“height: 369px; width: 712px;”></img></p>
|
121
93
|
|
122
|
-
<
|
94
|
+
<p>The RSpec test-time only approach constrained only to test-time.</p>
|
123
95
|
|
124
|
-
<
|
96
|
+
<h3 id="label-RSpec+Setup">RSpec Setup</h3>
|
125
97
|
|
126
|
-
<p>
|
98
|
+
<p>Use EnhancedErrors with RSpec for test-specific exception capturing, ideal for CI and local testing without impacting production.</p>
|
127
99
|
|
128
100
|
<pre class="code ruby"><code class="ruby">
|
129
101
|
<span class='const'>RSpec</span><span class='period'>.</span><span class='id identifier rubyid_configure'>configure</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_config'>config</span><span class='op'>|</span>
|
130
|
-
|
131
|
-
|
132
|
-
</span> <span class='id identifier rubyid_config'>config</span><span class='period'>.</span><span class='id identifier rubyid_before'>before</span><span class='lparen'>(</span><span class='symbol'>:suite</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
133
|
-
<span class='const'>RSpec</span><span class='op'>::</span><span class='const'>Core</span><span class='op'>::</span><span class='const'>Example</span><span class='period'>.</span><span class='id identifier rubyid_prepend'>prepend</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="Enhanced.html" title="Enhanced (module)">Enhanced</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Enhanced/Integrations.html" title="Enhanced::Integrations (module)">Integrations</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Enhanced/Integrations/RSpecErrorFailureMessage.html" title="Enhanced::Integrations::RSpecErrorFailureMessage (module)">RSpecErrorFailureMessage</a></span></span><span class='rparen'>)</span>
|
102
|
+
<span class='id identifier rubyid_config'>config</span><span class='period'>.</span><span class='id identifier rubyid_before'>before</span><span class='lparen'>(</span><span class='symbol'>:example</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid__example'>_example</span><span class='op'>|</span>
|
103
|
+
<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_start_rspec_binding_capture'><span class='object_link'><a href="EnhancedErrors.html#start_rspec_binding_capture-class_method" title="EnhancedErrors.start_rspec_binding_capture (method)">start_rspec_binding_capture</a></span></span>
|
134
104
|
<span class='kw'>end</span>
|
135
|
-
|
105
|
+
|
136
106
|
<span class='id identifier rubyid_config'>config</span><span class='period'>.</span><span class='id identifier rubyid_before'>before</span><span class='lparen'>(</span><span class='symbol'>:example</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid__example'>_example</span><span class='op'>|</span>
|
137
107
|
<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_start_rspec_binding_capture'><span class='object_link'><a href="EnhancedErrors.html#start_rspec_binding_capture-class_method" title="EnhancedErrors.start_rspec_binding_capture (method)">start_rspec_binding_capture</a></span></span>
|
138
108
|
<span class='kw'>end</span>
|
139
109
|
|
140
110
|
<span class='id identifier rubyid_config'>config</span><span class='period'>.</span><span class='id identifier rubyid_after'>after</span><span class='lparen'>(</span><span class='symbol'>:example</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_example'>example</span><span class='op'>|</span>
|
141
|
-
<span class='
|
111
|
+
<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_override_rspec_message'><span class='object_link'><a href="EnhancedErrors.html#override_rspec_message-class_method" title="EnhancedErrors.override_rspec_message (method)">override_rspec_message</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_example'>example</span><span class='comma'>,</span> <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_stop_rspec_binding_capture'><span class='object_link'><a href="EnhancedErrors.html#stop_rspec_binding_capture-class_method" title="EnhancedErrors.stop_rspec_binding_capture (method)">stop_rspec_binding_capture</a></span></span><span class='rparen'>)</span>
|
142
112
|
<span class='kw'>end</span>
|
143
|
-
|
144
113
|
<span class='kw'>end</span>
|
145
114
|
</code></pre>
|
146
115
|
|
147
|
-
<
|
116
|
+
<p><br></p>
|
148
117
|
|
149
|
-
<
|
118
|
+
<h2 id="label-MiniTest+Setup">MiniTest Setup</h2>
|
150
119
|
|
151
|
-
<
|
120
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>enhanced_errors</span><span class='tstring_end'>'</span></span>
|
121
|
+
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>enhanced/minitest_patch</span><span class='tstring_end'>'</span></span>
|
152
122
|
|
153
|
-
<
|
123
|
+
<span class='comment'># Once the patch is loaded, it should just work!
|
124
|
+
</span></code></pre>
|
154
125
|
|
155
|
-
<p
|
126
|
+
<p><br></p>
|
156
127
|
|
157
|
-
<
|
128
|
+
<h3 id="label-Enhanced+Errors+In+Everyday+Ruby+Exceptions-3A">Enhanced Errors In Everyday Ruby Exceptions:</h3>
|
158
129
|
|
159
|
-
<
|
130
|
+
<pre class="code ruby"><code class="ruby">
|
131
|
+
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>enhanced_errors</span><span class='tstring_end'>'</span></span>
|
132
|
+
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>awesome_print</span><span class='tstring_end'>'</span></span> <span class='comment'># Optional, for better output
|
133
|
+
</span>
|
134
|
+
<span class='comment'># Enable capturing of variables at exception at raise-time. The .captured_variables method
|
135
|
+
</span><span class='comment'># is added to all Exceptions and gets populated with in-scope variables and values on `raise`
|
136
|
+
</span>
|
137
|
+
<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_enhance_exceptions!'><span class='object_link'><a href="EnhancedErrors.html#enhance_exceptions!-class_method" title="EnhancedErrors.enhance_exceptions! (method)">enhance_exceptions!</a></span></span>
|
138
|
+
|
139
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_foo'>foo</span>
|
140
|
+
<span class='kw'>begin</span>
|
141
|
+
<span class='id identifier rubyid_myvar'>myvar</span> <span class='op'>=</span> <span class='int'>0</span>
|
142
|
+
<span class='ivar'>@myinstance</span> <span class='op'>=</span> <span class='int'>10</span>
|
143
|
+
<span class='id identifier rubyid_foo'>foo</span> <span class='op'>=</span> <span class='ivar'>@myinstance</span> <span class='op'>/</span> <span class='id identifier rubyid_myvar'>myvar</span>
|
144
|
+
<span class='kw'>rescue</span> <span class='op'>=></span> <span class='id identifier rubyid_e'>e</span>
|
145
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_e'>e</span><span class='period'>.</span><span class='id identifier rubyid_captured_variables'>captured_variables</span>
|
146
|
+
<span class='kw'>end</span>
|
147
|
+
<span class='kw'>end</span>
|
148
|
+
|
149
|
+
<span class='id identifier rubyid_foo'>foo</span>
|
150
|
+
</code></pre>
|
151
|
+
|
152
|
+
<h3 id="label-Enhancing+.message">Enhancing .message</h3>
|
153
|
+
|
154
|
+
<p>EnhancedErrors can append the captured variable description onto every Exception’s .message method with</p>
|
155
|
+
|
156
|
+
<pre class="code ruby"><code class="ruby"><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_enhance_exceptions'>enhance_exceptions</span><span class='lparen'>(</span><span class='label'>override_messages:</span> <span class='kw'>true</span><span class='rparen'>)</span>
|
157
|
+
</code></pre>
|
158
|
+
|
159
|
+
<p>This captures unanticipated exceptions without modifying all your error handlers. This approach can be used to get detailed logs when problems happen in something like a cron-job.</p>
|
160
|
+
|
161
|
+
<p>The tradeoff of this approach is that if you have expectations in your tests/specs around exception messages, those may break. Also, if you are doing something like storing the errors in a database, they could be <em>much</em> longer and that may pose an issue on field lengths. Or if you are writing your logs to Datadog, New Relic, Splunk, etc, log messages for errors will be longer, and you should consider what data/PII you are sharing.</p>
|
160
162
|
|
161
163
|
<p>Ideally, use exception.captured_variables instead.</p>
|
162
164
|
|
163
165
|
<pre class="code ruby"><code class="ruby"><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_enhance_exceptions!'><span class='object_link'><a href="EnhancedErrors.html#enhance_exceptions!-class_method" title="EnhancedErrors.enhance_exceptions! (method)">enhance_exceptions!</a></span></span><span class='lparen'>(</span><span class='label'>override_messages:</span> <span class='kw'>true</span><span class='rparen'>)</span>
|
164
166
|
</code></pre>
|
165
167
|
|
168
|
+
<h4 id="label-Output-3A">Output:</h4>
|
169
|
+
|
170
|
+
<p><img src=“./doc/images/enhanced-error.png” style=“height: 215px; width: 429px;”></img> <br></p>
|
171
|
+
|
166
172
|
<h2 id="label-Features">Features</h2>
|
167
173
|
<ul><li>
|
168
174
|
<p><strong>Pure Ruby</strong>: No external dependencies, C extensions, or C API calls.</p>
|
@@ -184,23 +190,17 @@
|
|
184
190
|
<p><strong>Lightweight</strong>: Minimal performance impact, as tracing is only active during exception raising.</p>
|
185
191
|
</li></ul>
|
186
192
|
|
187
|
-
<p>EnhancedErrors
|
193
|
+
<p>EnhancedErrors use-cases:</p>
|
188
194
|
<ul><li>
|
189
|
-
<p
|
190
|
-
</li><li>
|
191
|
-
<p><strong>Debug</strong> a complex application erroring deep in the stack when you can’t tell where the error originates.</p>
|
195
|
+
<p>Catch data-driven bugs without needing re-runs or extensive logging.</p>
|
192
196
|
</li><li>
|
193
|
-
<p
|
197
|
+
<p>Debug deep-stack errors and reduce mean time to resolution (MTTR).</p>
|
194
198
|
</li><li>
|
195
|
-
<p
|
199
|
+
<p>Handle CI failures faster by skipping reproduction steps.</p>
|
196
200
|
</li><li>
|
197
|
-
<p
|
201
|
+
<p>Address elusive “Heisenbugs” by capturing error context preemptively.</p>
|
198
202
|
</li><li>
|
199
|
-
<p
|
200
|
-
</li><li>
|
201
|
-
<p><strong>Unknown Unknowns</strong> - you can’t pre-emptively log variables from failure cases you never imagined.</p>
|
202
|
-
</li><li>
|
203
|
-
<p><strong>Cron jobs</strong> and <strong>daemons</strong> - when it fails for unknown reasons at 4am, check the log and fix–it probably has what you need. Note that</p>
|
203
|
+
<p>Debug cron jobs and daemons with rich, failure-specific logs.</p>
|
204
204
|
</li></ul>
|
205
205
|
|
206
206
|
<h2 id="label-Installation">Installation</h2>
|
@@ -232,11 +232,11 @@
|
|
232
232
|
</span><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_enhance_exceptions!'><span class='object_link'><a href="EnhancedErrors.html#enhance_exceptions!-class_method" title="EnhancedErrors.enhance_exceptions! (method)">enhance_exceptions!</a></span></span><span class='lparen'>(</span><span class='label'>override_messages:</span> <span class='kw'>true</span><span class='rparen'>)</span>
|
233
233
|
</code></pre>
|
234
234
|
|
235
|
-
<p>
|
235
|
+
<p>This captures all exceptions and their surrounding context. It also overrides the .message to display the variables.</p>
|
236
236
|
|
237
|
-
<p>If modifying your exception handlers is an option, it is better <em>not</em> to use
|
237
|
+
<p>If modifying your exception handlers is an option, it is better <em>not</em> to use but instead just use the exception.captured_variables, which is a string describing what was found.</p>
|
238
238
|
|
239
|
-
<p>Note
|
239
|
+
<p>Note: a minimalistic approach is taken to generating the capture string. If no qualifying variables were present, you won’t see any message additions!</p>
|
240
240
|
|
241
241
|
<h3 id="label-Configuration+Options">Configuration Options</h3>
|
242
242
|
|
@@ -256,8 +256,6 @@
|
|
256
256
|
<p><code>max_length</code>: Sets the maximum length of the captured_variables string (default: <code>2500</code>).</p>
|
257
257
|
</li></ul>
|
258
258
|
|
259
|
-
<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>
|
260
|
-
|
261
259
|
<h3 id="label-Environment-Based+Defaults">Environment-Based Defaults</h3>
|
262
260
|
|
263
261
|
<p>EnhancedErrors adjusts its default settings based on the environment:</p>
|
@@ -378,7 +376,7 @@
|
|
378
376
|
|
379
377
|
<p>While this is close to “Things that don’t descend from StandardError”, it’s not exactly that.</p>
|
380
378
|
|
381
|
-
<p>
|
379
|
+
<p>By default, many noisy instance variables are ignored in the default skip list. If you want to see every instance variable, you’ll need to clear out the skip list.</p>
|
382
380
|
|
383
381
|
<h3 id="label-Capture+Levels">Capture Levels</h3>
|
384
382
|
|
@@ -434,13 +432,11 @@
|
|
434
432
|
|
435
433
|
<p>The captured data is available in .captured_variables, to provide context for debugging.</p>
|
436
434
|
<ul><li>
|
437
|
-
<p>EnhancedErrors does not persist captured data
|
435
|
+
<p>EnhancedErrors does not persist captured data–it only keep it in memory for the lifetime of the exception.</p>
|
438
436
|
</li><li>
|
439
|
-
<p>There are benchmarks around Tracepoint in the benchmark folder. Targeted tracepoints seem to be very cheap
|
437
|
+
<p>There are benchmarks around Tracepoint in the benchmark folder. Targeted tracepoints seem to be very cheap–as in, you can hit them ten thousand+ times a second without heavy overhead.</p>
|
440
438
|
</li></ul>
|
441
439
|
|
442
|
-
<p>*</p>
|
443
|
-
|
444
440
|
<h2 id="label-Awesome+Print">Awesome Print</h2>
|
445
441
|
|
446
442
|
<p>EnhancedErrors automatically uses the <a href="https://github.com/awesome-print/awesome_print">awesome_print</a> gem to format the captured data, <strong><em>if</em></strong> it is installed and available. If not, error enhancement will work, but the output may be less pretty (er, awesome). AwesomePrint is not required directly by EnhancedErrors, so you will need to add it to your Gemfile if you want to use it.</p>
|
@@ -454,26 +450,26 @@
|
|
454
450
|
|
455
451
|
<p><a href="https://github.com/banister/binding_of_caller">binding_of_caller</a> or <a href="https://github.com/pry/pry">Pry</a> or <a href="https://github.com/BetterErrors/better_errors">better_errors</a>?</p>
|
456
452
|
|
457
|
-
<p>First off, these gems are
|
453
|
+
<p>First off, these gems are a-m-a-z-i-n-g!!! I use them every day–kudos to their creators and maintainers!</p>
|
458
454
|
|
459
|
-
<p>
|
455
|
+
<p>EnhancedErrors is intended as an every-day driver for <strong>non-interactive</strong> variable inspection.</p>
|
460
456
|
|
461
|
-
<p>
|
457
|
+
<p>I want extra details when I run into a problem I <strong>didn’t anticipate ahead of time</strong>. To make that work, it has to be able to safely be ‘on’ ahead of time, and gather data in a way I naturally will retain without requiring extra preparation I obviously didn’t know to do.</p>
|
462
458
|
<ul><li>
|
463
|
-
<p>
|
459
|
+
<p>EnhancedErrors won’t interrupt CI, but it lets me know what happened <em>without</em> reproduction steps</p>
|
464
460
|
</li><li>
|
465
|
-
<p>
|
461
|
+
<p>EnhancedErrors could, theoretically, also be fine in production (if data security, redaction, PII, access, and encryption concerns were all addressed. Big list, but another option is to selectively enable targeted capture.</p>
|
466
462
|
</li><li>
|
467
463
|
<p>Has decent performance characteristics</p>
|
468
464
|
</li><li>
|
469
465
|
<p><strong>Only</strong> becomes active in exception raise/rescue scenarios</p>
|
470
466
|
</li></ul>
|
471
467
|
|
472
|
-
<p>This gem could have been implemented using binding_of_caller, or the gem it depends on, <a href="https://rubygems.org/gems/debug_inspector/versions/1.1.0?locale=en">debug_inspector</a>. However, the recommendation is not to use those in production as they use C API extensions. This doesn’t.
|
468
|
+
<p>This gem could have been implemented using binding_of_caller, or the gem it depends on, <a href="https://rubygems.org/gems/debug_inspector/versions/1.1.0?locale=en">debug_inspector</a>. However, the recommendation is not to use those in production as they use C API extensions. This doesn’t. EnhancedErrors selectively uses Ruby’s TracePoint binding capture very narrowly with no other C API or dependencies, and only to target Exceptions. It operates in a narrow scope–becoming active only when exceptions are raised.</p>
|
473
469
|
|
474
470
|
<h2 id="label-Performance+Considerations">Performance Considerations</h2>
|
475
471
|
<ul><li>
|
476
|
-
<p><strong>
|
472
|
+
<p><strong>Small Overhead</strong>: Since TracePoint is only activated during exception raising and rescuing, the performance impact is negligible during normal operation. (Benchmark included)</p>
|
477
473
|
</li><li>
|
478
474
|
<p><strong>TBD</strong>: Memory considerations. This does capture data when an exception happens. EnhancedErrors hides under the bed when it sees <strong>NoMemoryError</strong>.</p>
|
479
475
|
</li><li>
|
@@ -490,7 +486,7 @@
|
|
490
486
|
</div></div>
|
491
487
|
|
492
488
|
<div id="footer">
|
493
|
-
Generated on
|
489
|
+
Generated on Sun Dec 15 22:33:19 2024 by
|
494
490
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
495
491
|
0.9.37 (ruby-3.1.3).
|
496
492
|
</div>
|
data/doc/method_list.html
CHANGED
@@ -87,6 +87,22 @@
|
|
87
87
|
</li>
|
88
88
|
|
89
89
|
|
90
|
+
<li class="even ">
|
91
|
+
<div class="item">
|
92
|
+
<span class='object_link'><a href="EnhancedErrors.html#capture_events_count-class_method" title="EnhancedErrors.capture_events_count (method)">capture_events_count</a></span>
|
93
|
+
<small>EnhancedErrors</small>
|
94
|
+
</div>
|
95
|
+
</li>
|
96
|
+
|
97
|
+
|
98
|
+
<li class="odd ">
|
99
|
+
<div class="item">
|
100
|
+
<span class='object_link'><a href="EnhancedErrors.html#capture_events_count=-class_method" title="EnhancedErrors.capture_events_count= (method)">capture_events_count=</a></span>
|
101
|
+
<small>EnhancedErrors</small>
|
102
|
+
</div>
|
103
|
+
</li>
|
104
|
+
|
105
|
+
|
90
106
|
<li class="even ">
|
91
107
|
<div class="item">
|
92
108
|
<span class='object_link'><a href="EnhancedErrors.html#capture_rescue-class_method" title="EnhancedErrors.capture_rescue (method)">capture_rescue</a></span>
|
@@ -96,6 +112,14 @@
|
|
96
112
|
|
97
113
|
|
98
114
|
<li class="odd ">
|
115
|
+
<div class="item">
|
116
|
+
<span class='object_link'><a href="EnhancedErrors.html#capture_rescue=-class_method" title="EnhancedErrors.capture_rescue= (method)">capture_rescue=</a></span>
|
117
|
+
<small>EnhancedErrors</small>
|
118
|
+
</div>
|
119
|
+
</li>
|
120
|
+
|
121
|
+
|
122
|
+
<li class="even ">
|
99
123
|
<div class="item">
|
100
124
|
<span class='object_link'><a href="Exception.html#captured_variables-instance_method" title="Exception#captured_variables (method)">#captured_variables</a></span>
|
101
125
|
<small>Exception</small>
|
@@ -103,6 +127,14 @@
|
|
103
127
|
</li>
|
104
128
|
|
105
129
|
|
130
|
+
<li class="odd ">
|
131
|
+
<div class="item">
|
132
|
+
<span class='object_link'><a href="EnhancedErrors.html#class_to_string-class_method" title="EnhancedErrors.class_to_string (method)">class_to_string</a></span>
|
133
|
+
<small>EnhancedErrors</small>
|
134
|
+
</div>
|
135
|
+
</li>
|
136
|
+
|
137
|
+
|
106
138
|
<li class="even ">
|
107
139
|
<div class="item">
|
108
140
|
<span class='object_link'><a href="Enhanced/Colors.html#code-class_method" title="Enhanced::Colors.code (method)">code</a></span>
|
@@ -137,7 +169,7 @@
|
|
137
169
|
|
138
170
|
<li class="even ">
|
139
171
|
<div class="item">
|
140
|
-
<span class='object_link'><a href="EnhancedErrors.html#
|
172
|
+
<span class='object_link'><a href="EnhancedErrors.html#eligible_for_capture-class_method" title="EnhancedErrors.eligible_for_capture (method)">eligible_for_capture</a></span>
|
141
173
|
<small>EnhancedErrors</small>
|
142
174
|
</div>
|
143
175
|
</li>
|
@@ -145,7 +177,7 @@
|
|
145
177
|
|
146
178
|
<li class="odd ">
|
147
179
|
<div class="item">
|
148
|
-
<span class='object_link'><a href="EnhancedErrors.html#
|
180
|
+
<span class='object_link'><a href="EnhancedErrors.html#enabled-class_method" title="EnhancedErrors.enabled (method)">enabled</a></span>
|
149
181
|
<small>EnhancedErrors</small>
|
150
182
|
</div>
|
151
183
|
</li>
|
@@ -153,15 +185,15 @@
|
|
153
185
|
|
154
186
|
<li class="even ">
|
155
187
|
<div class="item">
|
156
|
-
<span class='object_link'><a href="
|
157
|
-
<small>
|
188
|
+
<span class='object_link'><a href="Enhanced/Colors.html#enabled=-class_method" title="Enhanced::Colors.enabled= (method)">enabled=</a></span>
|
189
|
+
<small>Enhanced::Colors</small>
|
158
190
|
</div>
|
159
191
|
</li>
|
160
192
|
|
161
193
|
|
162
194
|
<li class="odd ">
|
163
195
|
<div class="item">
|
164
|
-
<span class='object_link'><a href="Enhanced/Colors.html#enabled
|
196
|
+
<span class='object_link'><a href="Enhanced/Colors.html#enabled%3F-class_method" title="Enhanced::Colors.enabled? (method)">enabled?</a></span>
|
165
197
|
<small>Enhanced::Colors</small>
|
166
198
|
</div>
|
167
199
|
</li>
|
@@ -169,15 +201,15 @@
|
|
169
201
|
|
170
202
|
<li class="even ">
|
171
203
|
<div class="item">
|
172
|
-
<span class='object_link'><a href="
|
173
|
-
<small>
|
204
|
+
<span class='object_link'><a href="EnhancedErrors.html#enhance_exceptions!-class_method" title="EnhancedErrors.enhance_exceptions! (method)">enhance_exceptions!</a></span>
|
205
|
+
<small>EnhancedErrors</small>
|
174
206
|
</div>
|
175
207
|
</li>
|
176
208
|
|
177
209
|
|
178
210
|
<li class="odd ">
|
179
211
|
<div class="item">
|
180
|
-
<span class='object_link'><a href="EnhancedErrors.html#
|
212
|
+
<span class='object_link'><a href="EnhancedErrors.html#format-class_method" title="EnhancedErrors.format (method)">format</a></span>
|
181
213
|
<small>EnhancedErrors</small>
|
182
214
|
</div>
|
183
215
|
</li>
|
@@ -185,15 +217,15 @@
|
|
185
217
|
|
186
218
|
<li class="even ">
|
187
219
|
<div class="item">
|
188
|
-
<span class='object_link'><a href="
|
189
|
-
<small>
|
220
|
+
<span class='object_link'><a href="EnhancedErrors.html#get_default_format_for_environment-class_method" title="EnhancedErrors.get_default_format_for_environment (method)">get_default_format_for_environment</a></span>
|
221
|
+
<small>EnhancedErrors</small>
|
190
222
|
</div>
|
191
223
|
</li>
|
192
224
|
|
193
225
|
|
194
226
|
<li class="odd ">
|
195
227
|
<div class="item">
|
196
|
-
<span class='object_link'><a href="EnhancedErrors.html#
|
228
|
+
<span class='object_link'><a href="EnhancedErrors.html#increment_capture_events_count-class_method" title="EnhancedErrors.increment_capture_events_count (method)">increment_capture_events_count</a></span>
|
197
229
|
<small>EnhancedErrors</small>
|
198
230
|
</div>
|
199
231
|
</li>
|
@@ -201,13 +233,37 @@
|
|
201
233
|
|
202
234
|
<li class="even ">
|
203
235
|
<div class="item">
|
204
|
-
<span class='object_link'><a href="EnhancedErrors.html#
|
236
|
+
<span class='object_link'><a href="EnhancedErrors.html#is_a_minitest%3F-class_method" title="EnhancedErrors.is_a_minitest? (method)">is_a_minitest?</a></span>
|
205
237
|
<small>EnhancedErrors</small>
|
206
238
|
</div>
|
207
239
|
</li>
|
208
240
|
|
209
241
|
|
210
242
|
<li class="odd ">
|
243
|
+
<div class="item">
|
244
|
+
<span class='object_link'><a href="EnhancedErrors.html#is_rspec_example%3F-class_method" title="EnhancedErrors.is_rspec_example? (method)">is_rspec_example?</a></span>
|
245
|
+
<small>EnhancedErrors</small>
|
246
|
+
</div>
|
247
|
+
</li>
|
248
|
+
|
249
|
+
|
250
|
+
<li class="even ">
|
251
|
+
<div class="item">
|
252
|
+
<span class='object_link'><a href="EnhancedErrors.html#max_capture_events-class_method" title="EnhancedErrors.max_capture_events (method)">max_capture_events</a></span>
|
253
|
+
<small>EnhancedErrors</small>
|
254
|
+
</div>
|
255
|
+
</li>
|
256
|
+
|
257
|
+
|
258
|
+
<li class="odd ">
|
259
|
+
<div class="item">
|
260
|
+
<span class='object_link'><a href="EnhancedErrors.html#max_capture_events=-class_method" title="EnhancedErrors.max_capture_events= (method)">max_capture_events=</a></span>
|
261
|
+
<small>EnhancedErrors</small>
|
262
|
+
</div>
|
263
|
+
</li>
|
264
|
+
|
265
|
+
|
266
|
+
<li class="even ">
|
211
267
|
<div class="item">
|
212
268
|
<span class='object_link'><a href="EnhancedErrors.html#max_length-class_method" title="EnhancedErrors.max_length (method)">max_length</a></span>
|
213
269
|
<small>EnhancedErrors</small>
|
@@ -215,6 +271,14 @@
|
|
215
271
|
</li>
|
216
272
|
|
217
273
|
|
274
|
+
<li class="odd ">
|
275
|
+
<div class="item">
|
276
|
+
<span class='object_link'><a href="EnhancedErrors.html#mutex-class_method" title="EnhancedErrors.mutex (method)">mutex</a></span>
|
277
|
+
<small>EnhancedErrors</small>
|
278
|
+
</div>
|
279
|
+
</li>
|
280
|
+
|
281
|
+
|
218
282
|
<li class="even ">
|
219
283
|
<div class="item">
|
220
284
|
<span class='object_link'><a href="EnhancedErrors.html#on_capture-class_method" title="EnhancedErrors.on_capture (method)">on_capture</a></span>
|
@@ -256,6 +320,14 @@
|
|
256
320
|
|
257
321
|
|
258
322
|
<li class="odd ">
|
323
|
+
<div class="item">
|
324
|
+
<span class='object_link'><a href="Minitest.html#original_run_one_method-class_method" title="Minitest.original_run_one_method (method)">original_run_one_method</a></span>
|
325
|
+
<small>Minitest</small>
|
326
|
+
</div>
|
327
|
+
</li>
|
328
|
+
|
329
|
+
|
330
|
+
<li class="even ">
|
259
331
|
<div class="item">
|
260
332
|
<span class='object_link'><a href="EnhancedErrors.html#override_exception_message-class_method" title="EnhancedErrors.override_exception_message (method)">override_exception_message</a></span>
|
261
333
|
<small>EnhancedErrors</small>
|
@@ -263,7 +335,7 @@
|
|
263
335
|
</li>
|
264
336
|
|
265
337
|
|
266
|
-
<li class="
|
338
|
+
<li class="odd ">
|
267
339
|
<div class="item">
|
268
340
|
<span class='object_link'><a href="EnhancedErrors.html#override_messages-class_method" title="EnhancedErrors.override_messages (method)">override_messages</a></span>
|
269
341
|
<small>EnhancedErrors</small>
|
@@ -271,6 +343,30 @@
|
|
271
343
|
</li>
|
272
344
|
|
273
345
|
|
346
|
+
<li class="even ">
|
347
|
+
<div class="item">
|
348
|
+
<span class='object_link'><a href="EnhancedErrors.html#override_rspec_message-class_method" title="EnhancedErrors.override_rspec_message (method)">override_rspec_message</a></span>
|
349
|
+
<small>EnhancedErrors</small>
|
350
|
+
</div>
|
351
|
+
</li>
|
352
|
+
|
353
|
+
|
354
|
+
<li class="odd ">
|
355
|
+
<div class="item">
|
356
|
+
<span class='object_link'><a href="EnhancedErrors.html#reset_capture_events_count-class_method" title="EnhancedErrors.reset_capture_events_count (method)">reset_capture_events_count</a></span>
|
357
|
+
<small>EnhancedErrors</small>
|
358
|
+
</div>
|
359
|
+
</li>
|
360
|
+
|
361
|
+
|
362
|
+
<li class="even ">
|
363
|
+
<div class="item">
|
364
|
+
<span class='object_link'><a href="Minitest.html#run_one_method-class_method" title="Minitest.run_one_method (method)">run_one_method</a></span>
|
365
|
+
<small>Minitest</small>
|
366
|
+
</div>
|
367
|
+
</li>
|
368
|
+
|
369
|
+
|
274
370
|
<li class="odd ">
|
275
371
|
<div class="item">
|
276
372
|
<span class='object_link'><a href="EnhancedErrors.html#running_in_ci%3F-class_method" title="EnhancedErrors.running_in_ci? (method)">running_in_ci?</a></span>
|
@@ -304,6 +400,14 @@
|
|
304
400
|
|
305
401
|
|
306
402
|
<li class="odd ">
|
403
|
+
<div class="item">
|
404
|
+
<span class='object_link'><a href="EnhancedErrors.html#start_minitest_binding_capture-class_method" title="EnhancedErrors.start_minitest_binding_capture (method)">start_minitest_binding_capture</a></span>
|
405
|
+
<small>EnhancedErrors</small>
|
406
|
+
</div>
|
407
|
+
</li>
|
408
|
+
|
409
|
+
|
410
|
+
<li class="even ">
|
307
411
|
<div class="item">
|
308
412
|
<span class='object_link'><a href="EnhancedErrors.html#start_rspec_binding_capture-class_method" title="EnhancedErrors.start_rspec_binding_capture (method)">start_rspec_binding_capture</a></span>
|
309
413
|
<small>EnhancedErrors</small>
|
@@ -311,6 +415,14 @@
|
|
311
415
|
</li>
|
312
416
|
|
313
417
|
|
418
|
+
<li class="odd ">
|
419
|
+
<div class="item">
|
420
|
+
<span class='object_link'><a href="EnhancedErrors.html#stop_minitest_binding_capture-class_method" title="EnhancedErrors.stop_minitest_binding_capture (method)">stop_minitest_binding_capture</a></span>
|
421
|
+
<small>EnhancedErrors</small>
|
422
|
+
</div>
|
423
|
+
</li>
|
424
|
+
|
425
|
+
|
314
426
|
<li class="even ">
|
315
427
|
<div class="item">
|
316
428
|
<span class='object_link'><a href="EnhancedErrors.html#stop_rspec_binding_capture-class_method" title="EnhancedErrors.stop_rspec_binding_capture (method)">stop_rspec_binding_capture</a></span>
|
@@ -82,7 +82,7 @@
|
|
82
82
|
<p class="children">
|
83
83
|
|
84
84
|
|
85
|
-
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Enhanced.html" title="Enhanced (module)">Enhanced</a></span>
|
85
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Enhanced.html" title="Enhanced (module)">Enhanced</a></span>, <span class='object_link'><a href="Minitest.html" title="Minitest (module)">Minitest</a></span>
|
86
86
|
|
87
87
|
|
88
88
|
|
@@ -122,7 +122,7 @@
|
|
122
122
|
</div>
|
123
123
|
|
124
124
|
<div id="footer">
|
125
|
-
Generated on
|
125
|
+
Generated on Sun Dec 15 22:33:19 2024 by
|
126
126
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
127
127
|
0.9.37 (ruby-3.1.3).
|
128
128
|
</div>
|
data/enhanced_errors.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "enhanced_errors"
|
3
|
-
spec.version = "2.
|
3
|
+
spec.version = "2.1.1"
|
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."
|
@@ -21,7 +21,10 @@ Gem::Specification.new do |spec|
|
|
21
21
|
end
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
+
# For development on this gem
|
24
25
|
spec.add_development_dependency "awesome_print", "~> 1.0"
|
25
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
26
27
|
spec.add_development_dependency 'yard', '~> 0.9'
|
28
|
+
spec.add_development_dependency 'minitest'
|
29
|
+
|
27
30
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require './lib/enhanced_errors'
|
2
2
|
require 'awesome_print' # Optional, for better output
|
3
3
|
|
4
|
+
# Demonstrates enhancing exceptions in normal day to day Ruby usage
|
5
|
+
# from this folder: ruby demo_exception_enhancement.rb
|
6
|
+
|
4
7
|
EnhancedErrors.enhance_exceptions!(override_messages: true, capture_events: [:raise, :rescue])
|
5
8
|
|
6
9
|
def foo
|
@@ -24,7 +27,6 @@ rescue Exception => e
|
|
24
27
|
puts e.message
|
25
28
|
end
|
26
29
|
|
27
|
-
|
28
30
|
puts "\n--- Example with raise ---\n\n\n"
|
29
31
|
|
30
32
|
foo
|