enhanced_errors 2.0.1 → 2.0.3

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.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "enhanced_errors"
3
- spec.version = "2.0.1"
3
+ spec.version = "2.0.3"
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."
@@ -22,7 +22,7 @@ class EnhancedErrors
22
22
  :override_messages
23
23
 
24
24
  GEMS_REGEX = %r{[\/\\]gems[\/\\]}
25
- DEFAULT_MAX_LENGTH = 2500
25
+ DEFAULT_MAX_LENGTH = 3000
26
26
 
27
27
  # Maximum binding infos we will track per-exception instance. This is intended as an extra
28
28
  # safety rail, not a normal scenario.
@@ -30,6 +30,8 @@ class EnhancedErrors
30
30
 
31
31
  # Add @__memoized and @__inspect_output to the skip list so they don't appear in output
32
32
  RSPEC_SKIP_LIST = Set.new([
33
+ :@assertions,
34
+ :@integration_session,
33
35
  :@example,
34
36
  :@fixture_cache,
35
37
  :@fixture_cache_key,
@@ -38,6 +40,7 @@ class EnhancedErrors
38
40
  :@loaded_fixtures,
39
41
  :@connection_subscriber,
40
42
  :@saved_pool_configs,
43
+ :@assertion_instance,
41
44
  :@legacy_saved_pool_configs,
42
45
  :@matcher_definitions,
43
46
  :@__memoized,
@@ -50,11 +53,13 @@ class EnhancedErrors
50
53
  :@association_cache,
51
54
  :@readonly,
52
55
  :@previously_new_record,
56
+ :@routes, # usually just shows #<ActionDispatch::Routing::RouteSet:0x000000016087d708>
53
57
  :@destroyed,
54
58
  :@marked_for_destruction,
55
59
  :@destroyed_by_association,
56
60
  :@primary_key,
57
61
  :@strict_loading,
62
+ :@assertion_instance,
58
63
  :@strict_loading_mode,
59
64
  :@mutations_before_last_save,
60
65
  :@mutations_from_database,
@@ -62,7 +67,8 @@ class EnhancedErrors
62
67
  :@predicate_builder,
63
68
  :@generated_relation_method,
64
69
  :@find_by_statement_cache,
65
- :@arel_table
70
+ :@arel_table,
71
+ :@response_klass,
66
72
  ])
67
73
 
68
74
  @enabled = false
@@ -192,10 +198,14 @@ class EnhancedErrors
192
198
 
193
199
  @rspec_tracepoint = TracePoint.new(:b_return) do |tp|
194
200
  # This is super-kluge-y and should be replaced with... something TBD
195
- if tp.self.class.name =~ /RSpec::ExampleGroups::[A-Z0-9]+.*/ &&
201
+
202
+ # fixes cases where class and name are screwed up or overridden
203
+ name = determine_object_name(tp)
204
+
205
+ if name =~ /RSpec::ExampleGroups::[A-Z0-9]+.*/ &&
196
206
  tp.method_id.nil? &&
197
- !(tp.path =~ /rspec/) &&
198
- tp.path =~ /_spec\.rb$/
207
+ !(tp.path.to_s =~ /rspec/) &&
208
+ tp.path.to_s =~ /_spec\.rb$/
199
209
  @rspec_example_binding = tp.binding
200
210
  end
201
211
  end
@@ -562,27 +572,43 @@ class EnhancedErrors
562
572
  value = locals.include?(name) ? safe_local_variable_get(bind, name) : nil
563
573
  "#{name}=#{safe_inspect(value)}"
564
574
  rescue => e
565
- "#{name}=#<Error getting argument: #{e.message}>"
575
+ "#{name}=[Error getting argument: #{e.message}]"
566
576
  end.join(", ")
567
577
  rescue => e
568
- "#<Error getting arguments: #{e.message}>"
578
+ "[Error getting arguments: #{e.message}]"
569
579
  end
570
580
  end
571
581
 
572
- def determine_object_name(tp, method_name)
573
- if tp.self.is_a?(Class) && tp.self.singleton_class == tp.defined_class
574
- "#{safe_to_s(tp.self)}.#{method_name}"
575
- else
576
- "#{safe_to_s(tp.self.class.name)}##{method_name}"
582
+ def determine_object_name(tp, method_name = '')
583
+ begin
584
+ # These tricks are used to get around the fact that `tp.self` can be a class that is
585
+ # wired up with method_missing where every direct call alters the class. This is true
586
+ # on certain builders or config objects and caused problems.
587
+
588
+ # Directly bind and call the `class` method to avoid triggering `method_missing`
589
+ self_class = Object.instance_method(:class).bind(tp.self).call
590
+
591
+ # Similarly, bind and call `singleton_class` safely
592
+ singleton_class = Object.instance_method(:singleton_class).bind(tp.self).call
593
+
594
+ if self_class && tp.defined_class == singleton_class
595
+ object_identifier = safe_to_s(tp.self)
596
+ method_suffix = method_name && !method_name.empty? ? ".#{method_name}" : ""
597
+ "#{object_identifier}#{method_suffix}"
598
+ else
599
+ object_class_name = safe_to_s(self_class.name || 'UnknownClass')
600
+ method_suffix = method_name && !method_name.empty? ? "##{method_name}" : ""
601
+ "#{object_class_name}#{method_suffix}"
602
+ end
603
+ rescue Exception => e
604
+ '[ErrorGettingName]'
577
605
  end
578
- rescue => e
579
- "#<Error inspecting value: #{e.message}>"
580
606
  end
581
607
 
582
608
  def get_global_variable_value(var)
583
609
  var.is_a?(Symbol) ? eval("#{var}") : nil
584
610
  rescue => e
585
- "#<Error getting value for #{var}>"
611
+ "[Error getting value for #{var}]"
586
612
  end
587
613
 
588
614
  def method_and_args_desc(method_info)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enhanced_errors
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Beland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-09 00:00:00.000000000 Z
11
+ date: 2024-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -70,11 +70,12 @@ files:
70
70
  - benchmark/benchmark.rb
71
71
  - benchmark/memory_bench.rb
72
72
  - benchmark/stackprofile.rb
73
- - doc/Binding.html
74
- - doc/Colors.html
75
- - doc/Debugging.html
73
+ - doc/Enhanced.html
74
+ - doc/Enhanced/Colors.html
75
+ - doc/Enhanced/Integrations.html
76
+ - doc/Enhanced/Integrations/RSpecErrorFailureMessage.html
76
77
  - doc/EnhancedErrors.html
77
- - doc/ErrorEnhancements.html
78
+ - doc/Exception.html
78
79
  - doc/_index.html
79
80
  - doc/class_list.html
80
81
  - doc/css/common.css
@@ -83,9 +84,6 @@ files:
83
84
  - doc/file.README.html
84
85
  - doc/file_list.html
85
86
  - doc/frames.html
86
- - doc/images/enhance.png
87
- - doc/images/enhanced-error.png
88
- - doc/images/enhanced-spec.png
89
87
  - doc/index.html
90
88
  - doc/js/app.js
91
89
  - doc/js/full_list.js
data/doc/Debugging.html DELETED
@@ -1,181 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>
7
- Module: Debugging
8
-
9
- &mdash; Documentation by YARD 0.9.37
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="css/style.css" type="text/css" />
14
-
15
- <link rel="stylesheet" href="css/common.css" type="text/css" />
16
-
17
- <script type="text/javascript">
18
- pathId = "Debugging";
19
- relpath = '';
20
- </script>
21
-
22
-
23
- <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
-
25
- <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
-
27
-
28
- </head>
29
- <body>
30
- <div class="nav_wrap">
31
- <iframe id="nav" src="class_list.html?1"></iframe>
32
- <div id="resizer"></div>
33
- </div>
34
-
35
- <div id="main" tabindex="-1">
36
- <div id="header">
37
- <div id="menu">
38
-
39
- <a href="_index.html">Index (D)</a> &raquo;
40
-
41
-
42
- <span class="title">Debugging</span>
43
-
44
- </div>
45
-
46
- <div id="search">
47
-
48
- <a class="full_list_link" id="class_list_link"
49
- href="class_list.html">
50
-
51
- <svg width="24" height="24">
52
- <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
- <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
- <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
- </svg>
56
- </a>
57
-
58
- </div>
59
- <div class="clear"></div>
60
- </div>
61
-
62
- <div id="content"><h1>Module: Debugging
63
-
64
-
65
-
66
- </h1>
67
- <div class="box_info">
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
- <dl>
78
- <dt>Included in:</dt>
79
- <dd><span class='object_link'><a href="Binding.html" title="Binding (class)">Binding</a></span></dd>
80
- </dl>
81
-
82
-
83
-
84
- <dl>
85
- <dt>Defined in:</dt>
86
- <dd>lib/binding.rb</dd>
87
- </dl>
88
-
89
- </div>
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
- <h2>
100
- Instance Method Summary
101
- <small><a href="#" class="summary_toggle">collapse</a></small>
102
- </h2>
103
-
104
- <ul class="summary">
105
-
106
- <li class="public ">
107
- <span class="summary_signature">
108
-
109
- <a href="#let_vars_hash-instance_method" title="#let_vars_hash (instance method)">#<strong>let_vars_hash</strong> &#x21d2; Object </a>
110
-
111
-
112
-
113
- </span>
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
- <span class="summary_desc"><div class='inline'></div></span>
124
-
125
- </li>
126
-
127
-
128
- </ul>
129
-
130
-
131
-
132
-
133
- <div id="instance_method_details" class="method_details_list">
134
- <h2>Instance Method Details</h2>
135
-
136
-
137
- <div class="method_details first">
138
- <h3 class="signature first" id="let_vars_hash-instance_method">
139
-
140
- #<strong>let_vars_hash</strong> &#x21d2; <tt>Object</tt>
141
-
142
-
143
-
144
-
145
-
146
- </h3><table class="source_code">
147
- <tr>
148
- <td>
149
- <pre class="lines">
150
-
151
-
152
- 2
153
- 3
154
- 4
155
- 5</pre>
156
- </td>
157
- <td>
158
- <pre class="code"><span class="info file"># File 'lib/binding.rb', line 2</span>
159
-
160
- <span class='kw'>def</span> <span class='id identifier rubyid_let_vars_hash'>let_vars_hash</span>
161
- <span class='id identifier rubyid_memoized_values'>memoized_values</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_receiver'>receiver</span><span class='period'>.</span><span class='id identifier rubyid_instance_variable_get'>instance_variable_get</span><span class='lparen'>(</span><span class='symbol'>:@__memoized</span><span class='rparen'>)</span><span class='op'>&amp;.</span><span class='id identifier rubyid_instance_variable_get'>instance_variable_get</span><span class='lparen'>(</span><span class='symbol'>:@memoized</span><span class='rparen'>)</span>
162
- <span class='id identifier rubyid_memoized_values'>memoized_values</span> <span class='op'>&amp;&amp;</span> <span class='op'>!</span><span class='id identifier rubyid_memoized_values'>memoized_values</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span> <span class='op'>?</span> <span class='id identifier rubyid_memoized_values'>memoized_values</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span> <span class='op'>:</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
163
- <span class='kw'>end</span></pre>
164
- </td>
165
- </tr>
166
- </table>
167
- </div>
168
-
169
- </div>
170
-
171
- </div>
172
-
173
- <div id="footer">
174
- Generated on Sun Nov 10 12:01:14 2024 by
175
- <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
176
- 0.9.37 (ruby-3.1.3).
177
- </div>
178
-
179
- </div>
180
- </body>
181
- </html>
@@ -1,258 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>
7
- Module: ErrorEnhancements
8
-
9
- &mdash; Documentation by YARD 0.9.37
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="css/style.css" type="text/css" />
14
-
15
- <link rel="stylesheet" href="css/common.css" type="text/css" />
16
-
17
- <script type="text/javascript">
18
- pathId = "ErrorEnhancements";
19
- relpath = '';
20
- </script>
21
-
22
-
23
- <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
-
25
- <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
-
27
-
28
- </head>
29
- <body>
30
- <div class="nav_wrap">
31
- <iframe id="nav" src="class_list.html?1"></iframe>
32
- <div id="resizer"></div>
33
- </div>
34
-
35
- <div id="main" tabindex="-1">
36
- <div id="header">
37
- <div id="menu">
38
-
39
- <a href="_index.html">Index (E)</a> &raquo;
40
-
41
-
42
- <span class="title">ErrorEnhancements</span>
43
-
44
- </div>
45
-
46
- <div id="search">
47
-
48
- <a class="full_list_link" id="class_list_link"
49
- href="class_list.html">
50
-
51
- <svg width="24" height="24">
52
- <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
- <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
- <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
- </svg>
56
- </a>
57
-
58
- </div>
59
- <div class="clear"></div>
60
- </div>
61
-
62
- <div id="content"><h1>Module: ErrorEnhancements
63
-
64
-
65
-
66
- </h1>
67
- <div class="box_info">
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
- <dl>
80
- <dt>Defined in:</dt>
81
- <dd>lib/error_enhancements.rb</dd>
82
- </dl>
83
-
84
- </div>
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
- <h2>
95
- Instance Method Summary
96
- <small><a href="#" class="summary_toggle">collapse</a></small>
97
- </h2>
98
-
99
- <ul class="summary">
100
-
101
- <li class="public ">
102
- <span class="summary_signature">
103
-
104
- <a href="#message-instance_method" title="#message (instance method)">#<strong>message</strong> &#x21d2; Object </a>
105
-
106
-
107
-
108
- </span>
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
- <span class="summary_desc"><div class='inline'></div></span>
119
-
120
- </li>
121
-
122
-
123
- <li class="public ">
124
- <span class="summary_signature">
125
-
126
- <a href="#variables_message-instance_method" title="#variables_message (instance method)">#<strong>variables_message</strong> &#x21d2; Object </a>
127
-
128
-
129
-
130
- </span>
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
- <span class="summary_desc"><div class='inline'></div></span>
141
-
142
- </li>
143
-
144
-
145
- </ul>
146
-
147
-
148
-
149
-
150
- <div id="instance_method_details" class="method_details_list">
151
- <h2>Instance Method Details</h2>
152
-
153
-
154
- <div class="method_details first">
155
- <h3 class="signature first" id="message-instance_method">
156
-
157
- #<strong>message</strong> &#x21d2; <tt>Object</tt>
158
-
159
-
160
-
161
-
162
-
163
- </h3><table class="source_code">
164
- <tr>
165
- <td>
166
- <pre class="lines">
167
-
168
-
169
- 2
170
- 3
171
- 4
172
- 5
173
- 6
174
- 7
175
- 8
176
- 9
177
- 10
178
- 11</pre>
179
- </td>
180
- <td>
181
- <pre class="code"><span class="info file"># File 'lib/error_enhancements.rb', line 2</span>
182
-
183
- <span class='kw'>def</span> <span class='id identifier rubyid_message'>message</span>
184
- <span class='id identifier rubyid_original_message'>original_message</span> <span class='op'>=</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='rparen'>)</span>
185
- <span class='kw'>if</span> <span class='id identifier rubyid_original_message'>original_message</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_variables_message'>variables_message</span><span class='rparen'>)</span>
186
- <span class='id identifier rubyid_original_message'>original_message</span>
187
- <span class='kw'>else</span>
188
- <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_original_message'>original_message</span><span class='embexpr_end'>}</span><span class='tstring_content'>\n</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_variables_message'>variables_message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
189
- <span class='kw'>end</span>
190
- <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
191
- <span class='id identifier rubyid_original_message'>original_message</span>
192
- <span class='kw'>end</span></pre>
193
- </td>
194
- </tr>
195
- </table>
196
- </div>
197
-
198
- <div class="method_details ">
199
- <h3 class="signature " id="variables_message-instance_method">
200
-
201
- #<strong>variables_message</strong> &#x21d2; <tt>Object</tt>
202
-
203
-
204
-
205
-
206
-
207
- </h3><table class="source_code">
208
- <tr>
209
- <td>
210
- <pre class="lines">
211
-
212
-
213
- 13
214
- 14
215
- 15
216
- 16
217
- 17
218
- 18
219
- 19
220
- 20
221
- 21
222
- 22
223
- 23
224
- 24</pre>
225
- </td>
226
- <td>
227
- <pre class="code"><span class="info file"># File 'lib/error_enhancements.rb', line 13</span>
228
-
229
- <span class='kw'>def</span> <span class='id identifier rubyid_variables_message'>variables_message</span>
230
- <span class='ivar'>@variables_message</span> <span class='op'>||=</span> <span class='kw'>begin</span>
231
- <span class='id identifier rubyid_bindings_of_interest'>bindings_of_interest</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
232
- <span class='kw'>if</span> <span class='kw'>defined?</span><span class='lparen'>(</span><span class='ivar'>@binding_infos</span><span class='rparen'>)</span> <span class='op'>&amp;&amp;</span> <span class='ivar'>@binding_infos</span> <span class='op'>&amp;&amp;</span> <span class='op'>!</span><span class='ivar'>@binding_infos</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
233
- <span class='id identifier rubyid_bindings_of_interest'>bindings_of_interest</span> <span class='op'>=</span> <span class='id identifier rubyid_select_binding_infos'>select_binding_infos</span><span class='lparen'>(</span><span class='ivar'>@binding_infos</span><span class='rparen'>)</span>
234
- <span class='kw'>end</span>
235
- <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_format'><span class='object_link'><a href="EnhancedErrors.html#format-class_method" title="EnhancedErrors.format (method)">format</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_bindings_of_interest'>bindings_of_interest</span><span class='rparen'>)</span>
236
- <span class='kw'>rescue</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
237
- <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Error in variables_message: </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>
238
- <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_end'>&quot;</span></span>
239
- <span class='kw'>end</span>
240
- <span class='kw'>end</span></pre>
241
- </td>
242
- </tr>
243
- </table>
244
- </div>
245
-
246
- </div>
247
-
248
- </div>
249
-
250
- <div id="footer">
251
- Generated on Sun Nov 10 12:01:14 2024 by
252
- <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
253
- 0.9.37 (ruby-3.1.3).
254
- </div>
255
-
256
- </div>
257
- </body>
258
- </html>
Binary file
Binary file
Binary file