enhanced_errors 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardoc/checksums +4 -4
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/enhanced_errors.gemspec +1 -1
- data/lib/enhanced/colors.rb +5 -3
- data/lib/enhanced_errors.rb +44 -42
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3897d29e868998ef225633f9f0f0f99a994b55563d65bff843ade348e7229bb9
|
4
|
+
data.tar.gz: 37f1db45f0c18c64846d396088f71bab2312b89da1a375b4d325309832983efc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b156387888d9479f5d474808a922127fbfc5c6ed7035c6d8ef552dabca39b550655e191bfc6f0f11d64db36ded66fe03619cca7eaff2f5b725abb3d106f07d87
|
7
|
+
data.tar.gz: ce0fcadb20a8be1f0b53921cf990e5c458ce6ba1099dc5b9ceff1c8459ab82b707234bfbf964b10036a5b37a33b0248337d0289005b0f32c61933efa25ef44de
|
data/.yardoc/checksums
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib/
|
2
|
-
lib/
|
3
|
-
lib/
|
4
|
-
lib/
|
1
|
+
lib/colors.rb a4314ef9531d4713907c3fea22955c943fdb8cf3
|
2
|
+
lib/binding.rb fdd7d5a2dd2edde22e3b10773510738dcdce4aeb
|
3
|
+
lib/enhanced_errors.rb d12ce0629f2565e5179ae5076be8a495e19ecda2
|
4
|
+
lib/error_enhancements.rb a97d0f139d35f6e1b5bf49386271b1f4cf71761c
|
data/.yardoc/object_types
CHANGED
Binary file
|
data/.yardoc/objects/root.dat
CHANGED
Binary file
|
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.0.
|
3
|
+
spec.version = "2.0.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."
|
data/lib/enhanced/colors.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Enhanced
|
2
2
|
class Colors
|
3
|
-
COLORS = { red: 31, green: 32, yellow: 33, blue: 34, purple: 35, cyan: 36, white: 0 }
|
3
|
+
COLORS = { red: 31, green: 32, yellow: 33, blue: 34, purple: 35, cyan: 36, white: 0 }.freeze
|
4
|
+
RESET_CODE = "\e[0m".freeze
|
4
5
|
|
5
6
|
class << self
|
6
7
|
def enabled?
|
@@ -12,11 +13,12 @@ module Enhanced
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def color(num, string)
|
15
|
-
|
16
|
+
return string unless @enabled
|
17
|
+
"#{code(num)}#{string}#{RESET_CODE}"
|
16
18
|
end
|
17
19
|
|
18
20
|
def code(num)
|
19
|
-
"\e[#{num}m"
|
21
|
+
"\e[#{num}m".freeze
|
20
22
|
end
|
21
23
|
|
22
24
|
COLORS.each do |color, code|
|
data/lib/enhanced_errors.rb
CHANGED
@@ -12,7 +12,6 @@ IGNORED_EXCEPTIONS = %w[SystemExit NoMemoryError SignalException Interrupt
|
|
12
12
|
RSpec::Matchers::BuiltIn::RaiseError
|
13
13
|
SystemStackError Psych::BadAlias]
|
14
14
|
|
15
|
-
|
16
15
|
class EnhancedErrors
|
17
16
|
extend ::Enhanced
|
18
17
|
|
@@ -22,17 +21,19 @@ class EnhancedErrors
|
|
22
21
|
:override_messages
|
23
22
|
|
24
23
|
GEMS_REGEX = %r{[\/\\]gems[\/\\]}
|
25
|
-
|
24
|
+
RSPEC_EXAMPLE_REGEXP = /RSpec::ExampleGroups::[A-Z0-9]+.*/
|
25
|
+
DEFAULT_MAX_LENGTH = 2000
|
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.
|
29
|
-
MAX_BINDING_INFOS =
|
29
|
+
MAX_BINDING_INFOS = 3
|
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
33
|
:@assertions,
|
34
34
|
:@integration_session,
|
35
35
|
:@example,
|
36
|
+
:@assertion_delegator,
|
36
37
|
:@fixture_cache,
|
37
38
|
:@fixture_cache_key,
|
38
39
|
:@fixture_connections,
|
@@ -45,7 +46,7 @@ class EnhancedErrors
|
|
45
46
|
:@matcher_definitions,
|
46
47
|
:@__memoized,
|
47
48
|
:@__inspect_output
|
48
|
-
])
|
49
|
+
]).freeze
|
49
50
|
|
50
51
|
RAILS_SKIP_LIST = Set.new([
|
51
52
|
:@new_record,
|
@@ -53,8 +54,11 @@ class EnhancedErrors
|
|
53
54
|
:@association_cache,
|
54
55
|
:@readonly,
|
55
56
|
:@previously_new_record,
|
56
|
-
:@
|
57
|
+
:@_routes, # usually just shows #<ActionDispatch::Routing::RouteSet:0x000000016087d708>
|
58
|
+
:@routes,
|
59
|
+
:@app,
|
57
60
|
:@destroyed,
|
61
|
+
:@response, #usually big, gets truncated anyway
|
58
62
|
:@marked_for_destruction,
|
59
63
|
:@destroyed_by_association,
|
60
64
|
:@primary_key,
|
@@ -63,13 +67,16 @@ class EnhancedErrors
|
|
63
67
|
:@strict_loading_mode,
|
64
68
|
:@mutations_before_last_save,
|
65
69
|
:@mutations_from_database,
|
70
|
+
:@integration_session,
|
66
71
|
:@relation_delegate_cache,
|
67
72
|
:@predicate_builder,
|
68
73
|
:@generated_relation_method,
|
69
74
|
:@find_by_statement_cache,
|
70
75
|
:@arel_table,
|
71
76
|
:@response_klass,
|
72
|
-
])
|
77
|
+
]).freeze
|
78
|
+
|
79
|
+
DEFAULT_SKIP_LIST = (RAILS_SKIP_LIST + RSPEC_SKIP_LIST).freeze
|
73
80
|
|
74
81
|
@enabled = false
|
75
82
|
|
@@ -92,11 +99,7 @@ class EnhancedErrors
|
|
92
99
|
end
|
93
100
|
|
94
101
|
def skip_list
|
95
|
-
@skip_list ||=
|
96
|
-
end
|
97
|
-
|
98
|
-
def default_skip_list
|
99
|
-
Set.new(RAILS_SKIP_LIST).merge(RSPEC_SKIP_LIST)
|
102
|
+
@skip_list ||= DEFAULT_SKIP_LIST.dup
|
100
103
|
end
|
101
104
|
|
102
105
|
# takes an exception and bindings, calculates the variables message
|
@@ -125,21 +128,19 @@ class EnhancedErrors
|
|
125
128
|
@original_global_variables = nil
|
126
129
|
@override_messages = override_messages
|
127
130
|
|
128
|
-
if enabled
|
131
|
+
if !enabled
|
129
132
|
@original_global_variables = nil
|
130
133
|
@enabled = false
|
131
134
|
@trace&.disable
|
132
|
-
@trace = nil
|
133
135
|
else
|
134
136
|
# if there's an old one, disable it before replacing it
|
135
137
|
# this seems to actually matter, although it seems like it
|
136
138
|
# shouldn't
|
137
139
|
@trace&.disable
|
138
|
-
@trace = nil
|
139
140
|
|
140
141
|
@enabled = true
|
141
142
|
@debug = debug
|
142
|
-
@original_global_variables = global_variables
|
143
|
+
@original_global_variables = global_variables if @debug
|
143
144
|
|
144
145
|
options.each do |key, value|
|
145
146
|
setter_method = "#{key}="
|
@@ -177,16 +178,15 @@ class EnhancedErrors
|
|
177
178
|
|
178
179
|
def safely_prepend_rspec_custom_failure_message
|
179
180
|
return if @rspec_failure_message_loaded
|
180
|
-
if defined?(RSpec::Core::Example)
|
181
|
+
if defined?(RSpec::Core::Example) && !RSpec::Core::Example < Enhanced::Integrations::RSpecErrorFailureMessage
|
181
182
|
RSpec::Core::Example.prepend(Enhanced::Integrations::RSpecErrorFailureMessage)
|
182
183
|
@rspec_failure_message_loaded = true
|
183
|
-
else
|
184
|
-
|
185
184
|
end
|
186
185
|
rescue => e
|
187
|
-
puts "Failed "
|
186
|
+
puts "Failed to prepend RSpec custom failure message: #{e.message}"
|
188
187
|
end
|
189
188
|
|
189
|
+
|
190
190
|
def start_rspec_binding_capture
|
191
191
|
@rspec_example_binding = nil
|
192
192
|
|
@@ -194,27 +194,25 @@ class EnhancedErrors
|
|
194
194
|
# the tracepoint without disabling it seemed to accumulate traces
|
195
195
|
# in the test suite where things are disabled and re-enabled often.
|
196
196
|
@rspec_tracepoint&.disable
|
197
|
-
@rspec_tracepoint = nil
|
198
197
|
|
199
198
|
@rspec_tracepoint = TracePoint.new(:b_return) do |tp|
|
200
199
|
# This is super-kluge-y and should be replaced with... something TBD
|
201
200
|
|
202
|
-
#
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
tp.path.to_s =~ /_spec\.rb$/
|
209
|
-
@rspec_example_binding = tp.binding
|
201
|
+
# early easy checks to nope out of the object name and other checks
|
202
|
+
if tp.method_id.nil? && !(tp.path.include?('rspec')) && tp.path.end_with?('_spec.rb')
|
203
|
+
# fixes cases where class and name are screwed up or overridden
|
204
|
+
if determine_object_name(tp) =~ RSPEC_EXAMPLE_REGEXP
|
205
|
+
@rspec_example_binding = tp.binding
|
206
|
+
end
|
210
207
|
end
|
208
|
+
|
211
209
|
end
|
210
|
+
|
212
211
|
@rspec_tracepoint.enable
|
213
212
|
end
|
214
213
|
|
215
214
|
def stop_rspec_binding_capture
|
216
215
|
@rspec_tracepoint&.disable
|
217
|
-
@rspec_tracepoint = nil
|
218
216
|
binding_info = convert_binding_to_binding_info(@rspec_example_binding) if @rspec_example_binding
|
219
217
|
@rspec_example_binding = nil
|
220
218
|
binding_info
|
@@ -261,8 +259,7 @@ class EnhancedErrors
|
|
261
259
|
|
262
260
|
# Apply skip list to remove @__memoized and @__inspect_output from output
|
263
261
|
# but only after extracting let variables.
|
264
|
-
|
265
|
-
binding_info
|
262
|
+
default_on_capture(binding_info)
|
266
263
|
end
|
267
264
|
|
268
265
|
def eligible_for_capture(&block)
|
@@ -358,12 +355,11 @@ class EnhancedErrors
|
|
358
355
|
end
|
359
356
|
|
360
357
|
def apply_skip_list(binding_info)
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
end
|
358
|
+
variables = binding_info[:variables]
|
359
|
+
variables[:instances]&.reject! { |var, _| skip_list.include?(var) || (var.to_s.start_with?('@_') && !@debug) }
|
360
|
+
variables[:locals]&.reject! { |var, _| skip_list.include?(var) }
|
361
|
+
return binding_info unless @debug
|
362
|
+
variables[:globals]&.reject! { |var, _| skip_list.include?(var) }
|
367
363
|
binding_info
|
368
364
|
end
|
369
365
|
|
@@ -394,7 +390,7 @@ class EnhancedErrors
|
|
394
390
|
|
395
391
|
instance_vars_to_display = variables[:instances] || {}
|
396
392
|
|
397
|
-
|
393
|
+
unless instance_vars_to_display.empty?
|
398
394
|
result += "\n#{Colors.green('Instances:')}\n#{variable_description(instance_vars_to_display)}"
|
399
395
|
end
|
400
396
|
|
@@ -520,11 +516,12 @@ class EnhancedErrors
|
|
520
516
|
end
|
521
517
|
|
522
518
|
def default_capture_events
|
519
|
+
return @default_capture_events if @default_capture_events
|
523
520
|
events = [:raise]
|
524
521
|
if capture_rescue && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3.0')
|
525
522
|
events << :rescue
|
526
523
|
end
|
527
|
-
|
524
|
+
@default_capture_events = events
|
528
525
|
end
|
529
526
|
|
530
527
|
def validate_and_set_capture_events(capture_events)
|
@@ -647,15 +644,20 @@ class EnhancedErrors
|
|
647
644
|
end
|
648
645
|
|
649
646
|
def safe_inspect(variable)
|
650
|
-
variable.inspect
|
647
|
+
str = variable.inspect
|
648
|
+
if str.length > 1200
|
649
|
+
str[0...1200] + '...'
|
650
|
+
else
|
651
|
+
str
|
652
|
+
end
|
651
653
|
rescue
|
652
654
|
safe_to_s(variable)
|
653
655
|
end
|
654
656
|
|
655
657
|
def safe_to_s(variable)
|
656
658
|
str = variable.to_s
|
657
|
-
if str.length >
|
658
|
-
str[0...
|
659
|
+
if str.length > 120
|
660
|
+
str[0...120] + '...'
|
659
661
|
else
|
660
662
|
str
|
661
663
|
end
|
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.
|
4
|
+
version: 2.0.5
|
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-
|
11
|
+
date: 2024-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|