enhanced_errors 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +103 -30
- data/benchmark/benchmark.rb +4 -4
- data/benchmark/stackprofile.rb +3 -3
- data/enhanced_errors.gemspec +2 -2
- data/examples/demo_spec.rb +32 -0
- data/examples/division_by_zero_example.rb +2 -2
- data/examples/example_spec.rb +21 -1
- data/lib/enhanced/colors.rb +30 -0
- data/lib/enhanced/exception.rb +45 -0
- data/lib/enhanced/integrations/rspec_error_failure_message.rb +13 -0
- data/lib/enhanced_errors.rb +253 -413
- metadata +8 -7
- data/lib/binding.rb +0 -12
- data/lib/colors.rb +0 -27
- data/lib/error_enhancements.rb +0 -59
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:
|
4
|
+
version: 2.0.0
|
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-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -42,14 +42,14 @@ dependencies:
|
|
42
42
|
name: yard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0.9'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.9'
|
55
55
|
description: 'EnhancedErrors will automatically enhance your errors with messages
|
@@ -93,12 +93,13 @@ files:
|
|
93
93
|
- doc/method_list.html
|
94
94
|
- doc/top-level-namespace.html
|
95
95
|
- enhanced_errors.gemspec
|
96
|
+
- examples/demo_spec.rb
|
96
97
|
- examples/division_by_zero_example.rb
|
97
98
|
- examples/example_spec.rb
|
98
|
-
- lib/
|
99
|
-
- lib/
|
99
|
+
- lib/enhanced/colors.rb
|
100
|
+
- lib/enhanced/exception.rb
|
101
|
+
- lib/enhanced/integrations/rspec_error_failure_message.rb
|
100
102
|
- lib/enhanced_errors.rb
|
101
|
-
- lib/error_enhancements.rb
|
102
103
|
homepage: https://github.com/ericbeland/enhanced_errors
|
103
104
|
licenses: []
|
104
105
|
metadata:
|
data/lib/binding.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# binding.rb
|
2
|
-
|
3
|
-
module Debugging
|
4
|
-
def let_vars_hash
|
5
|
-
memoized_values = self.receiver.instance_variable_get(:@__memoized)&.instance_variable_get(:@memoized)
|
6
|
-
memoized_values && !memoized_values.empty? ? memoized_values.dup : {}
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class Binding
|
11
|
-
include Debugging
|
12
|
-
end
|
data/lib/colors.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
class Colors
|
2
|
-
COLORS = { red: 31, green: 32, yellow: 33, blue: 34, purple: 35, cyan: 36, white: 0 }
|
3
|
-
|
4
|
-
class << self
|
5
|
-
def enabled?
|
6
|
-
@enabled
|
7
|
-
end
|
8
|
-
|
9
|
-
def enabled=(value)
|
10
|
-
@enabled = value
|
11
|
-
end
|
12
|
-
|
13
|
-
def color(num, string)
|
14
|
-
@enabled ? "#{code(num)}#{string}#{code(0)}" : string
|
15
|
-
end
|
16
|
-
|
17
|
-
def code(num)
|
18
|
-
"\e[#{num}m"
|
19
|
-
end
|
20
|
-
|
21
|
-
COLORS.each do |color, code|
|
22
|
-
define_method(color) do |str|
|
23
|
-
color(COLORS[color], str)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/lib/error_enhancements.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# error_enhancements.rb
|
2
|
-
|
3
|
-
module ErrorEnhancements
|
4
|
-
def message
|
5
|
-
original_message = begin
|
6
|
-
super()
|
7
|
-
rescue
|
8
|
-
''
|
9
|
-
end
|
10
|
-
vars_message = variables_message rescue ""
|
11
|
-
if original_message.include?(vars_message)
|
12
|
-
original_message
|
13
|
-
else
|
14
|
-
"#{original_message}\n#{vars_message}"
|
15
|
-
end
|
16
|
-
rescue => e
|
17
|
-
original_message || ''
|
18
|
-
end
|
19
|
-
|
20
|
-
def variables_message
|
21
|
-
@variables_message ||= begin
|
22
|
-
if @binding_infos&.any?
|
23
|
-
bindings_of_interest = select_binding_infos(@binding_infos)
|
24
|
-
EnhancedErrors.format(bindings_of_interest)
|
25
|
-
else
|
26
|
-
''
|
27
|
-
end
|
28
|
-
rescue
|
29
|
-
''
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def select_binding_infos(binding_infos)
|
36
|
-
# Preference:
|
37
|
-
# 1. First 'raise' binding that isn't from a library (gem).
|
38
|
-
# 2. If none, the first binding.
|
39
|
-
# 3. The last 'rescue' binding if available.
|
40
|
-
|
41
|
-
bindings_of_interest = []
|
42
|
-
|
43
|
-
first_app_raise = binding_infos.find do |info|
|
44
|
-
info[:capture_event] == 'raise' && !info[:library]
|
45
|
-
end
|
46
|
-
bindings_of_interest << first_app_raise if first_app_raise
|
47
|
-
|
48
|
-
if bindings_of_interest.empty? && binding_infos.first
|
49
|
-
bindings_of_interest << binding_infos.first
|
50
|
-
end
|
51
|
-
|
52
|
-
last_rescue = binding_infos.reverse.find do |info|
|
53
|
-
info[:capture_event] == 'rescue'
|
54
|
-
end
|
55
|
-
bindings_of_interest << last_rescue if last_rescue
|
56
|
-
|
57
|
-
bindings_of_interest
|
58
|
-
end
|
59
|
-
end
|