humanist-errors 1.0.3 → 1.0.4
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/README.md +21 -11
- data/dictionaries/humanist_errors.en.yml +2 -2
- data/dictionaries/humanist_errors.oops.yml +15 -0
- data/lib/humanist_errors/exception_extensions.rb +5 -7
- data/lib/humanist_errors/monkey.rb +1 -1
- data/lib/humanist_errors/regex_hash.rb +1 -1
- data/lib/humanist_errors/search.rb +4 -5
- data/lib/humanist_errors/version.rb +1 -1
- data/test/regex_hash_test.rb +2 -2
- data/test/search_test.rb +4 -4
- data/test/test_helper.rb +4 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5eeb0edb25690acd18d5bf9d3a952a7923a0b35
|
4
|
+
data.tar.gz: 7aa50ca45ba9097de3000de1173c317a6cd6d117
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c990c48eb6660e1184bc30f66fa47ad1066db7b30e4b16c8fdd1ef591c7c7d39d0786fc4dfa3cb1ed5301a60e11c019309b77f0a60b600a9f7523657d0e3884
|
7
|
+
data.tar.gz: 02d6c3d956fa6a0fd99e03535e0094956d8893a4b71425d4a05eec9da289220d0eee16692e47f4716d0357cfb406379ad144048bf312457e40267afdb4e07add
|
data/README.md
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
[](https://codeclimate.com/github/bgreg/humanist-errors)[](https://codeclimate.com/github/bgreg/humanist-errors)[](https://travis-ci.org/bgreg/humanist-errors)
|
2
2
|
|
3
|
-
#
|
3
|
+
# Error messages for Humans.
|
4
4
|
|
5
5
|
[](https://gitter.im/bgreg/humanist-errors?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
6
6
|
|
7
|
-
Humanist errors is a system for extending ruby exception messages.
|
7
|
+
Humanist errors is a system for extending ruby exception messages.
|
8
8
|
It will prepend the standard output with text defined in the humanist errors dictionary.
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
12
12
|
Add this line to your application's Gemfile:
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
```
|
14
|
+
gem 'humanist-errors'
|
15
|
+
|
17
16
|
|
18
17
|
And then execute:
|
19
18
|
|
@@ -23,15 +22,26 @@ Or install it yourself as:
|
|
23
22
|
|
24
23
|
$ gem install humanist-errors
|
25
24
|
|
25
|
+
|
26
26
|
## Usage
|
27
27
|
|
28
|
-
|
28
|
+
Require the library and monkey file
|
29
|
+
|
30
|
+
require humanist_errors
|
31
|
+
require humanist_errors/monkey
|
32
|
+
|
33
|
+
If you want to only want to see new errors in an isolated area
|
29
34
|
|
30
|
-
|
35
|
+
include HumanistErrors
|
36
|
+
|
37
|
+
Then your code in a human block:
|
38
|
+
|
39
|
+
```ruby
|
31
40
|
with_human_errors do
|
32
|
-
|
41
|
+
#....
|
33
42
|
end
|
34
43
|
```
|
44
|
+
|
35
45
|
This gem is intended for use in development and test environments only.
|
36
46
|
|
37
47
|
## Contributing
|
@@ -44,10 +54,10 @@ This gem is intended for use in development and test environments only.
|
|
44
54
|
|
45
55
|
|
46
56
|
## TODO
|
47
|
-
1)
|
57
|
+
1) add more errors to error_map
|
58
|
+
|
59
|
+
##### High level exception tree:
|
48
60
|
|
49
|
-
High level exception tree:
|
50
|
-
----
|
51
61
|
```ruby
|
52
62
|
Exception
|
53
63
|
NoMethodError
|
@@ -3,10 +3,10 @@
|
|
3
3
|
:open_quote: "It looks like you typed an open quote near the end of the file."
|
4
4
|
:string_formatter: "% string formatter requires a string argument on the left, and a format argument on the right"
|
5
5
|
:missing_argument: "You indicated that you wanted to send another argument, but we did not see anything."
|
6
|
-
:missing_block_closer: "
|
6
|
+
:missing_block_closer: "A block was started, but you forgot to add 'end'. Ruby tries to match every `do` with an `end`, but it reached the end of the file and a matching 'end' token was not found. To fix this, review all the 'do..end' pairs."
|
7
7
|
|
8
8
|
:no_method_error:
|
9
|
-
:undefined_method_for_nil: "
|
9
|
+
:undefined_method_for_nil: "You defined a variable with good intentions, then along the way, something turned it to nil."
|
10
10
|
|
11
11
|
:name_error:
|
12
12
|
:undefined_word: "You typed a random string that wasn't defined. It is not a method or variable in this class, or it's ancestors"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
:syntax_error:
|
2
|
+
:unexpected_semi_colon: "oops"
|
3
|
+
:open_quote: "oop"
|
4
|
+
:string_formatter: "oop"
|
5
|
+
:missing_argument: "oops"
|
6
|
+
:missing_block_closer: "oops"
|
7
|
+
|
8
|
+
:no_method_error:
|
9
|
+
:undefined_method_for_nil: "oops"
|
10
|
+
|
11
|
+
:name_error:
|
12
|
+
:undefined_word: "oops"
|
13
|
+
|
14
|
+
:zero_division_error:
|
15
|
+
:divide_by_zero: "oops"
|
@@ -1,17 +1,15 @@
|
|
1
1
|
module HumanistErrors
|
2
2
|
module ExceptionExtensions
|
3
3
|
def to_s
|
4
|
-
|
5
|
-
if
|
4
|
+
error = Search.run(self.class, super)
|
5
|
+
if :no_result == error
|
6
6
|
super
|
7
7
|
else
|
8
8
|
color = Color.new
|
9
|
-
"\n#{STARTING_TOKEN}"
|
10
|
-
"
|
11
|
-
"#{ENDING_TOKEN}" +
|
12
|
-
super
|
9
|
+
"\n\n#{STARTING_TOKEN}" \
|
10
|
+
" #{color.cyan(error)}\n" \
|
11
|
+
"#{ENDING_TOKEN}\n" + super
|
13
12
|
end
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
17
|
-
|
@@ -1 +1 @@
|
|
1
|
-
::Exception.
|
1
|
+
::Exception.__send__(:prepend, HumanistErrors::ExceptionExtensions)
|
@@ -1,12 +1,9 @@
|
|
1
1
|
module HumanistErrors
|
2
2
|
class Search
|
3
|
-
attr_accessor :found_error
|
4
|
-
attr_accessor :error_object, :ruby_error_message
|
5
3
|
|
6
4
|
def self.run(error_object, ruby_error_message)
|
7
5
|
searcher = new(error_object, ruby_error_message)
|
8
|
-
searcher.
|
9
|
-
searcher
|
6
|
+
searcher.find
|
10
7
|
end
|
11
8
|
|
12
9
|
def initialize(error_object, ruby_error_message)
|
@@ -21,7 +18,10 @@ module HumanistErrors
|
|
21
18
|
end
|
22
19
|
|
23
20
|
private
|
21
|
+
attr_reader :error_object, :ruby_error_message, :found_error
|
24
22
|
|
23
|
+
# turn a CamelCase word into an underscored
|
24
|
+
# symbol to make it nice for hash keys.
|
25
25
|
def keyify(error)
|
26
26
|
error.to_s
|
27
27
|
.gsub(/::/, '__')
|
@@ -33,4 +33,3 @@ module HumanistErrors
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
data/test/regex_hash_test.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class RegexHashTest < Minitest::Test
|
4
|
+
include HumanistErrorsSupport
|
4
5
|
|
5
6
|
def test_a_regex_search_happens_on_key_send
|
6
7
|
magic_string_hash = HumanistErrors::RegexHash[/findme/ => "hurray!"]
|
@@ -9,7 +10,6 @@ class RegexHashTest < Minitest::Test
|
|
9
10
|
|
10
11
|
def test_a_failure_when_key_is_not_found
|
11
12
|
magic_string_hash = HumanistErrors::RegexHash[/findme/ => "hurray!"]
|
12
|
-
|
13
|
-
assert(error.message.include?("Could not find Ruby message in dictionary: 1"))
|
13
|
+
assert_no_result(magic_string_hash['1'])
|
14
14
|
end
|
15
15
|
end
|
data/test/search_test.rb
CHANGED
@@ -2,17 +2,17 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class SearchTest < Minitest::Test
|
4
4
|
def test_finds_a_human_error
|
5
|
-
|
5
|
+
error = HumanistErrors::Search.run(
|
6
6
|
NameError,
|
7
7
|
"NameError: undefined local variable or method `asdf' for main:Object"
|
8
8
|
)
|
9
9
|
expected_result = HumanistErrors::MESSAGE_DICTIONARY[:name_error][:undefined_word]
|
10
|
-
assert(
|
10
|
+
assert(error == expected_result, "#{error.inspect} does not equal: #{expected_result.inspect}")
|
11
11
|
end
|
12
12
|
|
13
13
|
class DefinatelyNotARealException; end
|
14
14
|
def test_cannot_find_a_error_message
|
15
|
-
|
16
|
-
assert(
|
15
|
+
error = HumanistErrors::Search.run(DefinatelyNotARealException, "blah blah blah")
|
16
|
+
assert(error == :no_result, "#{error.inspect} does not equal: :no_result")
|
17
17
|
end
|
18
18
|
end
|
data/test/test_helper.rb
CHANGED
@@ -14,6 +14,10 @@ module HumanistErrorsSupport
|
|
14
14
|
assert(message != :no_result, "no result was found")
|
15
15
|
end
|
16
16
|
|
17
|
+
def assert_no_result(message)
|
18
|
+
assert(message == :no_result, "no result was found")
|
19
|
+
end
|
20
|
+
|
17
21
|
def assert_error_map(ruby_error, exception_symbol, error_symbol)
|
18
22
|
result = HumanistErrors::ERROR_MAPPER[exception_symbol][ruby_error]
|
19
23
|
assert_result(result)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: humanist-errors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg McGuirk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- README.md
|
55
55
|
- Rakefile
|
56
56
|
- dictionaries/humanist_errors.en.yml
|
57
|
+
- dictionaries/humanist_errors.oops.yml
|
57
58
|
- humanist-errors.gemspec
|
58
59
|
- lib/humanist_errors.rb
|
59
60
|
- lib/humanist_errors/colors.rb
|