eturem 0.5.2 → 0.5.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.
- checksums.yaml +4 -4
- data/.gitignore +9 -9
- data/CODE_OF_CONDUCT.md +74 -74
- data/Gemfile +7 -7
- data/LICENSE.txt +21 -21
- data/README.ja.md +223 -223
- data/README.md +31 -31
- data/Rakefile +11 -11
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/eturem.gemspec +30 -30
- data/lib/eturem.rb +79 -79
- data/lib/eturem/base.rb +7 -7
- data/lib/eturem/version.rb +3 -3
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6f7d954f618abe8fcf4f93cf3090a13ba9ef7ddca3c3ef56404e00e435c45432
|
|
4
|
+
data.tar.gz: 021fa72979dd1c3c1ea0a98b8d5fef4be838e7b70ccf1bfd9845cdb74d5a73e4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b3d9767cb1cee6cc3488c4a3ba10e2a28f8d3678c0248a55274d7e4541bcdd31882dca11ce731915a5c17b16a93750c0790043e6c3f967af522ebe3a72accd9b
|
|
7
|
+
data.tar.gz: eac6deef0d5b16d83c038bca2ea11b457fc7e6966c4867f2c1e85ecf781ab64d8329103b025bca75390d30fbb8b8b8b3a22ce2fe7c7e1991f0bf131d73899820
|
data/.gitignore
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/.bundle/
|
|
2
|
-
/.yardoc
|
|
3
|
-
/_yardoc/
|
|
4
|
-
/coverage/
|
|
5
|
-
/doc/
|
|
6
|
-
/pkg/
|
|
7
|
-
/spec/reports/
|
|
8
|
-
/tmp/
|
|
9
|
-
/Gemfile.lock
|
|
1
|
+
/.bundle/
|
|
2
|
+
/.yardoc
|
|
3
|
+
/_yardoc/
|
|
4
|
+
/coverage/
|
|
5
|
+
/doc/
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/tmp/
|
|
9
|
+
/Gemfile.lock
|
data/CODE_OF_CONDUCT.md
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
|
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
-
orientation.
|
|
11
|
-
|
|
12
|
-
## Our Standards
|
|
13
|
-
|
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
|
15
|
-
include:
|
|
16
|
-
|
|
17
|
-
* Using welcoming and inclusive language
|
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
|
19
|
-
* Gracefully accepting constructive criticism
|
|
20
|
-
* Focusing on what is best for the community
|
|
21
|
-
* Showing empathy towards other community members
|
|
22
|
-
|
|
23
|
-
Examples of unacceptable behavior by participants include:
|
|
24
|
-
|
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
-
advances
|
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
-
* Public or private harassment
|
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
|
30
|
-
address, without explicit permission
|
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
-
professional setting
|
|
33
|
-
|
|
34
|
-
## Our Responsibilities
|
|
35
|
-
|
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
-
response to any instances of unacceptable behavior.
|
|
39
|
-
|
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
-
threatening, offensive, or harmful.
|
|
45
|
-
|
|
46
|
-
## Scope
|
|
47
|
-
|
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
-
when an individual is representing the project or its community. Examples of
|
|
50
|
-
representing a project or community include using an official project e-mail
|
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
|
53
|
-
further defined and clarified by project maintainers.
|
|
54
|
-
|
|
55
|
-
## Enforcement
|
|
56
|
-
|
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
-
reported by contacting the project team at nodai2h.itc@gmail.com. All
|
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
|
63
|
-
|
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
-
members of the project's leadership.
|
|
67
|
-
|
|
68
|
-
## Attribution
|
|
69
|
-
|
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
-
|
|
73
|
-
[homepage]: http://contributor-covenant.org
|
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at nodai2h.itc@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
source "https://rubygems.org"
|
|
2
|
-
|
|
3
|
-
# Specify your gem's dependencies in eturem.gemspec
|
|
4
|
-
gemspec
|
|
5
|
-
|
|
6
|
-
gem "rake", "~> 12.0"
|
|
7
|
-
gem "minitest", "~> 5.0"
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
# Specify your gem's dependencies in eturem.gemspec
|
|
4
|
+
gemspec
|
|
5
|
+
|
|
6
|
+
gem "rake", "~> 12.0"
|
|
7
|
+
gem "minitest", "~> 5.0"
|
data/LICENSE.txt
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018-2020 nodai2hITC
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018-2020 nodai2hITC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.ja.md
CHANGED
|
@@ -1,223 +1,223 @@
|
|
|
1
|
-
# Eturem
|
|
2
|
-
|
|
3
|
-
Ruby のエラーメッセージを、初心者にわかりやすく表示するための gem です。
|
|
4
|
-
|
|
5
|
-
Easy To Understand Ruby Error Message の略。
|
|
6
|
-
|
|
7
|
-
## インストールと使用方法
|
|
8
|
-
|
|
9
|
-
$ gem install eturem
|
|
10
|
-
|
|
11
|
-
でインストールし、
|
|
12
|
-
|
|
13
|
-
$ ruby -returem/ja <your_script.rb>
|
|
14
|
-
|
|
15
|
-
または
|
|
16
|
-
|
|
17
|
-
$ eturem lang=ja <your_script.rb>
|
|
18
|
-
|
|
19
|
-
と使用すればよいのですが、最初に書いたとおり初心者が使用することを想定した gem ですので、そんなことを初心者に強いるのは酷というもの。だれか詳しい人が、事前に ```gem install eturem``` した上で、環境変数 RUBYOPT に ```-returem/ja``` を追加しておいてあげましょう。
|
|
20
|
-
|
|
21
|
-
## 使用するとどうなるか
|
|
22
|
-
|
|
23
|
-
* エラーメッセージが日本語で表示される。
|
|
24
|
-
* エラー箇所周辺が表示される。
|
|
25
|
-
* エラーの種類によっては、原因を特定するためのさらなる情報が表示される。
|
|
26
|
-
|
|
27
|
-
### 例1:SyntaxError
|
|
28
|
-
|
|
29
|
-
```ruby
|
|
30
|
-
if gets.to_i == 1
|
|
31
|
-
if gets.to_i == 2
|
|
32
|
-
puts "なんたらかんたら"
|
|
33
|
-
# 内側の if に対応する end を忘れてしまった!
|
|
34
|
-
end
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
通常の環境で実行すると、次のようなエラーが表示されます。
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
example1.rb:5: syntax error, unexpected end-of-input, expecting keyword_end
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
英語の苦手な人ではこの時点で拒否反応が出るでしょうし、そうでなくとも「end-of-input」や「keyword_end」が何を意味しているのか、初心者には掴みにくいのではないでしょうか。
|
|
44
|
-
|
|
45
|
-
Eturem を使用すると、次のようなエラー表示になります。
|
|
46
|
-
|
|
47
|
-
```
|
|
48
|
-
【エラー】ファイル"example1.rb" 5行目:
|
|
49
|
-
(ただし、実際のエラーの原因はおそらくもっと前にあります。)
|
|
50
|
-
構文エラーです。endが足りません。「if」に対応する「end」があるか確認してください。
|
|
51
|
-
3: puts "なんたらかんたら"
|
|
52
|
-
4: # 内側の if に対応する end を忘れてしまった!
|
|
53
|
-
=> 5: end
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
このように、日本語でわかりやすくエラーを表示してくれます。
|
|
57
|
-
|
|
58
|
-
### 例2:NameError
|
|
59
|
-
|
|
60
|
-
```ruby
|
|
61
|
-
prayer_life = 100
|
|
62
|
-
# ↑スペルミス!
|
|
63
|
-
# 中略
|
|
64
|
-
# ↓このスペルは正しいが、上でミスしたことでエラー発生。
|
|
65
|
-
if player_life > 0
|
|
66
|
-
# 後略
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
通常の環境で実行すると、次のようなエラーが表示されます。
|
|
70
|
-
|
|
71
|
-
```
|
|
72
|
-
example2.rb:5:in `<main>': undefined local variable or method `player_life' for main:Object (NameError)
|
|
73
|
-
Did you mean? prayer_life
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
did_you_mean のおかげで昔より格段にわかりやすくなったとはいえ、それでも英語に壁を感じる人はいますし、またこの例の場合実際にミスをしたのは1行目にもかかわらず「5行目でエラー」と表示されてしまうため、「え?5行目を何度見てもミスなんて無いよ?」と困ってしまう人もいるでしょう。
|
|
77
|
-
|
|
78
|
-
Eturem を使用すると、次のようなエラー表示になります。(実際には色付き)
|
|
79
|
-
|
|
80
|
-
```
|
|
81
|
-
【エラー】ファイル"example2.rb" 5行目:
|
|
82
|
-
変数/メソッド「player_life」は存在しません。「prayer_life」の入力ミスではありませんか?
|
|
83
|
-
1: prayer_life = 100
|
|
84
|
-
:
|
|
85
|
-
3: # 中略
|
|
86
|
-
4: # ↓このスペルは正しいが、上でミスしたことでエラー発生。
|
|
87
|
-
=> 5: if player_life > 0
|
|
88
|
-
6: # 後略
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
このように、エラー発生箇所周辺だけではなく、did_you_mean がサジェストしてくれた変数の使用行も同時に表示してくれるので、ミスをしたのが実は1行目であることに気付きやすくなるのではないでしょうか。
|
|
92
|
-
|
|
93
|
-
### 例3:ArgumentError
|
|
94
|
-
|
|
95
|
-
```ruby
|
|
96
|
-
def foo(a, b)
|
|
97
|
-
end
|
|
98
|
-
# 中略
|
|
99
|
-
foo(1)
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
通常の環境で実行すると、次のようなエラーが表示されます。
|
|
103
|
-
|
|
104
|
-
```
|
|
105
|
-
Traceback (most recent call last):
|
|
106
|
-
1: from example3.rb:4:in `<main>'
|
|
107
|
-
example3.rb:1:in `foo': wrong number of arguments (given 1, expected 2) (ArgumentError)
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
このように、ArgumentError のエラー発生行は、メソッド定義行(この場合1行目)になってしまいます。しかし実際に ArgumentError が発生するときの原因は、メソッド定義部分ではなく、呼び出し部分であることがほとんどではないでしょうか?
|
|
111
|
-
|
|
112
|
-
この例の場合 Traceback に「from example3.rb:4」と表示されてはいますが、初心者にはやはりわかりにくいのではないかと思われます。
|
|
113
|
-
|
|
114
|
-
Eturem を使用すると、次のようなエラー表示になります。
|
|
115
|
-
|
|
116
|
-
```
|
|
117
|
-
【エラー】ファイル"example3.rb" 4行目:
|
|
118
|
-
引数の数が正しくありません。「foo」は本来2個の引数を取りますが、1個の引数が渡されています。
|
|
119
|
-
2: end
|
|
120
|
-
3: # 中略
|
|
121
|
-
=> 4: foo(1)
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
このように、呼び出し行をエラー発生行として表示してくれます。
|
|
125
|
-
|
|
126
|
-
### 例4:warning
|
|
127
|
-
|
|
128
|
-
0.4.0 から、warning に対してもサポートができるようになりました。
|
|
129
|
-
|
|
130
|
-
```
|
|
131
|
-
【警告】ファイル"example4.rb" 2行目:
|
|
132
|
-
条件式部分で「 = 」が使われています。「 == 」の間違いではありませんか?
|
|
133
|
-
=> 2: puts "a" if a = 1
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
現状あまり多くの種類の警告に対応できてはいませんが、上記のように日本語での警告に加えて該当行を表示することができます。
|
|
137
|
-
|
|
138
|
-
### 例5:エラー発生時に自動で binding.irb
|
|
139
|
-
|
|
140
|
-
変数の値が不適切だったためにエラーが起きた可能性がある場合、エラーが起きた瞬間の変数の値を調べる必要があります。そうした際には「エラー発生箇所の直前に binding.irb を入れて調べる」という手がありますが、そうするとたまにしか起きないエラーの場合何度も binding.irb が動いてしまって面倒です。
|
|
141
|
-
|
|
142
|
-
そこで、後述する設定ファイル .eturem で設定するか、あるいはプログラム中に `$eturem_repl = "irb"` と入れておくことで、エラー発生時に自動的に binding.irb することができます。
|
|
143
|
-
|
|
144
|
-
なお、この機能だけを切り出した gem「[autoirb](https://github.com/nodai2hITC/autoirb)」もあります。
|
|
145
|
-
|
|
146
|
-
### その他細かなこと
|
|
147
|
-
|
|
148
|
-
#### 全角空白・全角記号による NameError
|
|
149
|
-
|
|
150
|
-
日本人ならきっと誰もがやったことがあり、そして意外と気付けない全角空白や全角記号によるエラー。通常の NameError の場合とは異なるメッセージでわかりやすくしています。(下の表示ではわかりませんが、実際には全角空白部分に下線が引かれています。)
|
|
151
|
-
|
|
152
|
-
```
|
|
153
|
-
【エラー】ファイル"example5.rb" 1行目:(NoMethodError)
|
|
154
|
-
スクリプト中に全角空白が混じっています。
|
|
155
|
-
=> 1: puts "こんにちは世界"
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
#### 大文字・小文字を間違えた場合の NameError
|
|
159
|
-
|
|
160
|
-
did_you_mean は、例えば `Time.now` と書くべきところを `time.now` と間違えて小文字で書いてしまった場合、 `Time` をサジェストしないようになっています。(サジェスト範囲を広げると誤反応が多くなるため、敢えてそうしているのだそうです。)
|
|
161
|
-
|
|
162
|
-
とはいえ、初心者は大文字小文字が区別されるという意識が無く、つい小文字で入力してしまうことが少なからずあるように思えます。そこでスペルが同一で大文字小文字のみが異なる場合に限り、定数もサジェスト対象になるようにしています。
|
|
163
|
-
|
|
164
|
-
```
|
|
165
|
-
【エラー】ファイル"example6.rb" 1行目:(NameError)
|
|
166
|
-
変数/メソッド「time」は存在しません。「Time」の入力ミスではありませんか?
|
|
167
|
-
=> 1: start_time = time.now
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
## .eturem ファイルによる設定
|
|
171
|
-
|
|
172
|
-
HOME またはカレントディレクトリに「.eturem」というファイルを用意すると、詳細設定ができます。(下の例の設定が、各項目を省略した際に使用される初期値です。)
|
|
173
|
-
|
|
174
|
-
```
|
|
175
|
-
enable: true
|
|
176
|
-
debug: false
|
|
177
|
-
lang: en
|
|
178
|
-
output_backtrace: true
|
|
179
|
-
output_original: true
|
|
180
|
-
output_script: true
|
|
181
|
-
override_warning: true
|
|
182
|
-
use_coderay: false
|
|
183
|
-
before_line_num: 2
|
|
184
|
-
after_line_num: 2
|
|
185
|
-
repl: nil
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
- enable: eturem の使用/不使用を切り替えます。
|
|
189
|
-
- debug: eturem 自体をデバッグするための機能なので、通常は使う必要はありません。
|
|
190
|
-
- lang: 表示言語を切り替えます。ただし `-returem/ja` のように言語を指定して使用した場合、この設定よりもそちらが優先されます。
|
|
191
|
-
- output_backtrace: バックトレース表示の有無を切り替えます。
|
|
192
|
-
- output_original: Ruby 本来のエラーメッセージの表示の有無を切り替えます。
|
|
193
|
-
- output_script: エラーの起きた個所のスクリプト表示の有無を切り替えます。
|
|
194
|
-
- override_warning: 警告に対してもわかりやすいメッセージを表示するかを設定します。
|
|
195
|
-
- before_line_num / after_line_num: スクリプト表示の際、エラー行の前後何行を表示するかを設定します。
|
|
196
|
-
- repl: irb または pry と書いておくと、エラー発生時に自動的に binding.irb / binding.pry します。
|
|
197
|
-
|
|
198
|
-
## 簡単な仕組み
|
|
199
|
-
|
|
200
|
-
```ruby
|
|
201
|
-
begin
|
|
202
|
-
load($PROGRAM_NAME)
|
|
203
|
-
rescue Exception => e
|
|
204
|
-
# エラー表示処理
|
|
205
|
-
end
|
|
206
|
-
exit
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
実際はもう少しいろいろやっていますが、このように本来のスクリプト実行が始まる前に `-returem` オプションで eturem を呼び出し、そこから `load` でスクリプトを実行しているのがポイントです。これにより、SyntaxError 等も取得できるようになっています。
|
|
210
|
-
|
|
211
|
-
## Contributing
|
|
212
|
-
|
|
213
|
-
「こう表示した方がよりわかりやすいのでは?」等のご意見ありましたら、よろしく御願いします。
|
|
214
|
-
|
|
215
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/nodai2hITC/eturem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
216
|
-
|
|
217
|
-
## License
|
|
218
|
-
|
|
219
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
220
|
-
|
|
221
|
-
## Code of Conduct
|
|
222
|
-
|
|
223
|
-
Everyone interacting in the Eturem project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nodai2hITC/eturem/blob/master/CODE_OF_CONDUCT.md).
|
|
1
|
+
# Eturem
|
|
2
|
+
|
|
3
|
+
Ruby のエラーメッセージを、初心者にわかりやすく表示するための gem です。
|
|
4
|
+
|
|
5
|
+
Easy To Understand Ruby Error Message の略。
|
|
6
|
+
|
|
7
|
+
## インストールと使用方法
|
|
8
|
+
|
|
9
|
+
$ gem install eturem
|
|
10
|
+
|
|
11
|
+
でインストールし、
|
|
12
|
+
|
|
13
|
+
$ ruby -returem/ja <your_script.rb>
|
|
14
|
+
|
|
15
|
+
または
|
|
16
|
+
|
|
17
|
+
$ eturem lang=ja <your_script.rb>
|
|
18
|
+
|
|
19
|
+
と使用すればよいのですが、最初に書いたとおり初心者が使用することを想定した gem ですので、そんなことを初心者に強いるのは酷というもの。だれか詳しい人が、事前に ```gem install eturem``` した上で、環境変数 RUBYOPT に ```-returem/ja``` を追加しておいてあげましょう。
|
|
20
|
+
|
|
21
|
+
## 使用するとどうなるか
|
|
22
|
+
|
|
23
|
+
* エラーメッセージが日本語で表示される。
|
|
24
|
+
* エラー箇所周辺が表示される。
|
|
25
|
+
* エラーの種類によっては、原因を特定するためのさらなる情報が表示される。
|
|
26
|
+
|
|
27
|
+
### 例1:SyntaxError
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
if gets.to_i == 1
|
|
31
|
+
if gets.to_i == 2
|
|
32
|
+
puts "なんたらかんたら"
|
|
33
|
+
# 内側の if に対応する end を忘れてしまった!
|
|
34
|
+
end
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
通常の環境で実行すると、次のようなエラーが表示されます。
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
example1.rb:5: syntax error, unexpected end-of-input, expecting keyword_end
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
英語の苦手な人ではこの時点で拒否反応が出るでしょうし、そうでなくとも「end-of-input」や「keyword_end」が何を意味しているのか、初心者には掴みにくいのではないでしょうか。
|
|
44
|
+
|
|
45
|
+
Eturem を使用すると、次のようなエラー表示になります。
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
【エラー】ファイル"example1.rb" 5行目:
|
|
49
|
+
(ただし、実際のエラーの原因はおそらくもっと前にあります。)
|
|
50
|
+
構文エラーです。endが足りません。「if」に対応する「end」があるか確認してください。
|
|
51
|
+
3: puts "なんたらかんたら"
|
|
52
|
+
4: # 内側の if に対応する end を忘れてしまった!
|
|
53
|
+
=> 5: end
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
このように、日本語でわかりやすくエラーを表示してくれます。
|
|
57
|
+
|
|
58
|
+
### 例2:NameError
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
prayer_life = 100
|
|
62
|
+
# ↑スペルミス!
|
|
63
|
+
# 中略
|
|
64
|
+
# ↓このスペルは正しいが、上でミスしたことでエラー発生。
|
|
65
|
+
if player_life > 0
|
|
66
|
+
# 後略
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
通常の環境で実行すると、次のようなエラーが表示されます。
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
example2.rb:5:in `<main>': undefined local variable or method `player_life' for main:Object (NameError)
|
|
73
|
+
Did you mean? prayer_life
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
did_you_mean のおかげで昔より格段にわかりやすくなったとはいえ、それでも英語に壁を感じる人はいますし、またこの例の場合実際にミスをしたのは1行目にもかかわらず「5行目でエラー」と表示されてしまうため、「え?5行目を何度見てもミスなんて無いよ?」と困ってしまう人もいるでしょう。
|
|
77
|
+
|
|
78
|
+
Eturem を使用すると、次のようなエラー表示になります。(実際には色付き)
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
【エラー】ファイル"example2.rb" 5行目:
|
|
82
|
+
変数/メソッド「player_life」は存在しません。「prayer_life」の入力ミスではありませんか?
|
|
83
|
+
1: prayer_life = 100
|
|
84
|
+
:
|
|
85
|
+
3: # 中略
|
|
86
|
+
4: # ↓このスペルは正しいが、上でミスしたことでエラー発生。
|
|
87
|
+
=> 5: if player_life > 0
|
|
88
|
+
6: # 後略
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
このように、エラー発生箇所周辺だけではなく、did_you_mean がサジェストしてくれた変数の使用行も同時に表示してくれるので、ミスをしたのが実は1行目であることに気付きやすくなるのではないでしょうか。
|
|
92
|
+
|
|
93
|
+
### 例3:ArgumentError
|
|
94
|
+
|
|
95
|
+
```ruby
|
|
96
|
+
def foo(a, b)
|
|
97
|
+
end
|
|
98
|
+
# 中略
|
|
99
|
+
foo(1)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
通常の環境で実行すると、次のようなエラーが表示されます。
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
Traceback (most recent call last):
|
|
106
|
+
1: from example3.rb:4:in `<main>'
|
|
107
|
+
example3.rb:1:in `foo': wrong number of arguments (given 1, expected 2) (ArgumentError)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
このように、ArgumentError のエラー発生行は、メソッド定義行(この場合1行目)になってしまいます。しかし実際に ArgumentError が発生するときの原因は、メソッド定義部分ではなく、呼び出し部分であることがほとんどではないでしょうか?
|
|
111
|
+
|
|
112
|
+
この例の場合 Traceback に「from example3.rb:4」と表示されてはいますが、初心者にはやはりわかりにくいのではないかと思われます。
|
|
113
|
+
|
|
114
|
+
Eturem を使用すると、次のようなエラー表示になります。
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
【エラー】ファイル"example3.rb" 4行目:
|
|
118
|
+
引数の数が正しくありません。「foo」は本来2個の引数を取りますが、1個の引数が渡されています。
|
|
119
|
+
2: end
|
|
120
|
+
3: # 中略
|
|
121
|
+
=> 4: foo(1)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
このように、呼び出し行をエラー発生行として表示してくれます。
|
|
125
|
+
|
|
126
|
+
### 例4:warning
|
|
127
|
+
|
|
128
|
+
0.4.0 から、warning に対してもサポートができるようになりました。
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
【警告】ファイル"example4.rb" 2行目:
|
|
132
|
+
条件式部分で「 = 」が使われています。「 == 」の間違いではありませんか?
|
|
133
|
+
=> 2: puts "a" if a = 1
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
現状あまり多くの種類の警告に対応できてはいませんが、上記のように日本語での警告に加えて該当行を表示することができます。
|
|
137
|
+
|
|
138
|
+
### 例5:エラー発生時に自動で binding.irb
|
|
139
|
+
|
|
140
|
+
変数の値が不適切だったためにエラーが起きた可能性がある場合、エラーが起きた瞬間の変数の値を調べる必要があります。そうした際には「エラー発生箇所の直前に binding.irb を入れて調べる」という手がありますが、そうするとたまにしか起きないエラーの場合何度も binding.irb が動いてしまって面倒です。
|
|
141
|
+
|
|
142
|
+
そこで、後述する設定ファイル .eturem で設定するか、あるいはプログラム中に `$eturem_repl = "irb"` と入れておくことで、エラー発生時に自動的に binding.irb することができます。
|
|
143
|
+
|
|
144
|
+
なお、この機能だけを切り出した gem「[autoirb](https://github.com/nodai2hITC/autoirb)」もあります。
|
|
145
|
+
|
|
146
|
+
### その他細かなこと
|
|
147
|
+
|
|
148
|
+
#### 全角空白・全角記号による NameError
|
|
149
|
+
|
|
150
|
+
日本人ならきっと誰もがやったことがあり、そして意外と気付けない全角空白や全角記号によるエラー。通常の NameError の場合とは異なるメッセージでわかりやすくしています。(下の表示ではわかりませんが、実際には全角空白部分に下線が引かれています。)
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
【エラー】ファイル"example5.rb" 1行目:(NoMethodError)
|
|
154
|
+
スクリプト中に全角空白が混じっています。
|
|
155
|
+
=> 1: puts "こんにちは世界"
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### 大文字・小文字を間違えた場合の NameError
|
|
159
|
+
|
|
160
|
+
did_you_mean は、例えば `Time.now` と書くべきところを `time.now` と間違えて小文字で書いてしまった場合、 `Time` をサジェストしないようになっています。(サジェスト範囲を広げると誤反応が多くなるため、敢えてそうしているのだそうです。)
|
|
161
|
+
|
|
162
|
+
とはいえ、初心者は大文字小文字が区別されるという意識が無く、つい小文字で入力してしまうことが少なからずあるように思えます。そこでスペルが同一で大文字小文字のみが異なる場合に限り、定数もサジェスト対象になるようにしています。
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
【エラー】ファイル"example6.rb" 1行目:(NameError)
|
|
166
|
+
変数/メソッド「time」は存在しません。「Time」の入力ミスではありませんか?
|
|
167
|
+
=> 1: start_time = time.now
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## .eturem ファイルによる設定
|
|
171
|
+
|
|
172
|
+
HOME またはカレントディレクトリに「.eturem」というファイルを用意すると、詳細設定ができます。(下の例の設定が、各項目を省略した際に使用される初期値です。)
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
enable: true
|
|
176
|
+
debug: false
|
|
177
|
+
lang: en
|
|
178
|
+
output_backtrace: true
|
|
179
|
+
output_original: true
|
|
180
|
+
output_script: true
|
|
181
|
+
override_warning: true
|
|
182
|
+
use_coderay: false
|
|
183
|
+
before_line_num: 2
|
|
184
|
+
after_line_num: 2
|
|
185
|
+
repl: nil
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
- enable: eturem の使用/不使用を切り替えます。
|
|
189
|
+
- debug: eturem 自体をデバッグするための機能なので、通常は使う必要はありません。
|
|
190
|
+
- lang: 表示言語を切り替えます。ただし `-returem/ja` のように言語を指定して使用した場合、この設定よりもそちらが優先されます。
|
|
191
|
+
- output_backtrace: バックトレース表示の有無を切り替えます。
|
|
192
|
+
- output_original: Ruby 本来のエラーメッセージの表示の有無を切り替えます。
|
|
193
|
+
- output_script: エラーの起きた個所のスクリプト表示の有無を切り替えます。
|
|
194
|
+
- override_warning: 警告に対してもわかりやすいメッセージを表示するかを設定します。
|
|
195
|
+
- before_line_num / after_line_num: スクリプト表示の際、エラー行の前後何行を表示するかを設定します。
|
|
196
|
+
- repl: irb または pry と書いておくと、エラー発生時に自動的に binding.irb / binding.pry します。
|
|
197
|
+
|
|
198
|
+
## 簡単な仕組み
|
|
199
|
+
|
|
200
|
+
```ruby
|
|
201
|
+
begin
|
|
202
|
+
load($PROGRAM_NAME)
|
|
203
|
+
rescue Exception => e
|
|
204
|
+
# エラー表示処理
|
|
205
|
+
end
|
|
206
|
+
exit
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
実際はもう少しいろいろやっていますが、このように本来のスクリプト実行が始まる前に `-returem` オプションで eturem を呼び出し、そこから `load` でスクリプトを実行しているのがポイントです。これにより、SyntaxError 等も取得できるようになっています。
|
|
210
|
+
|
|
211
|
+
## Contributing
|
|
212
|
+
|
|
213
|
+
「こう表示した方がよりわかりやすいのでは?」等のご意見ありましたら、よろしく御願いします。
|
|
214
|
+
|
|
215
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nodai2hITC/eturem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
|
|
219
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
220
|
+
|
|
221
|
+
## Code of Conduct
|
|
222
|
+
|
|
223
|
+
Everyone interacting in the Eturem project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nodai2hITC/eturem/blob/master/CODE_OF_CONDUCT.md).
|
data/README.md
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
# Eturem
|
|
2
|
-
|
|
3
|
-
Easy To Understand Ruby Error Message.
|
|
4
|
-
|
|
5
|
-
[日本語説明(こちらの方が詳細)](https://github.com/nodai2hITC/eturem/blob/master/README.ja.md)
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
install it yourself as:
|
|
10
|
-
|
|
11
|
-
$ gem install eturem
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
$ ruby -returem <your_script.rb>
|
|
16
|
-
|
|
17
|
-
or
|
|
18
|
-
|
|
19
|
-
$ eturem <your_script.rb>
|
|
20
|
-
|
|
21
|
-
## Contributing
|
|
22
|
-
|
|
23
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/nodai2hITC/eturem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
24
|
-
|
|
25
|
-
## License
|
|
26
|
-
|
|
27
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
28
|
-
|
|
29
|
-
## Code of Conduct
|
|
30
|
-
|
|
31
|
-
Everyone interacting in the Eturem project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nodai2hITC/eturem/blob/master/CODE_OF_CONDUCT.md).
|
|
1
|
+
# Eturem
|
|
2
|
+
|
|
3
|
+
Easy To Understand Ruby Error Message.
|
|
4
|
+
|
|
5
|
+
[日本語説明(こちらの方が詳細)](https://github.com/nodai2hITC/eturem/blob/master/README.ja.md)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
install it yourself as:
|
|
10
|
+
|
|
11
|
+
$ gem install eturem
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
$ ruby -returem <your_script.rb>
|
|
16
|
+
|
|
17
|
+
or
|
|
18
|
+
|
|
19
|
+
$ eturem <your_script.rb>
|
|
20
|
+
|
|
21
|
+
## Contributing
|
|
22
|
+
|
|
23
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nodai2hITC/eturem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
28
|
+
|
|
29
|
+
## Code of Conduct
|
|
30
|
+
|
|
31
|
+
Everyone interacting in the Eturem project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nodai2hITC/eturem/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
require "bundler/gem_tasks"
|
|
2
|
-
require "rake/testtask"
|
|
3
|
-
|
|
4
|
-
Rake::TestTask.new(:test) do |t|
|
|
5
|
-
t.libs << "test"
|
|
6
|
-
t.libs << "lib"
|
|
7
|
-
t.test_files = FileList["test/**/*_test.rb"]
|
|
8
|
-
t.warning = false
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
task :default => :test
|
|
1
|
+
require "bundler/gem_tasks"
|
|
2
|
+
require "rake/testtask"
|
|
3
|
+
|
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
|
5
|
+
t.libs << "test"
|
|
6
|
+
t.libs << "lib"
|
|
7
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
|
8
|
+
t.warning = false
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
task :default => :test
|
data/bin/console
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
require "eturem"
|
|
5
|
-
|
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
-
|
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
-
# require "pry"
|
|
11
|
-
# Pry.start
|
|
12
|
-
|
|
13
|
-
require "irb"
|
|
14
|
-
IRB.start(__FILE__)
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "eturem"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
set -euo pipefail
|
|
3
|
-
IFS=$'\n\t'
|
|
4
|
-
set -vx
|
|
5
|
-
|
|
6
|
-
bundle install
|
|
7
|
-
|
|
8
|
-
# Do any other automated setup that you need to do here
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
IFS=$'\n\t'
|
|
4
|
+
set -vx
|
|
5
|
+
|
|
6
|
+
bundle install
|
|
7
|
+
|
|
8
|
+
# Do any other automated setup that you need to do here
|
data/eturem.gemspec
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
require_relative 'lib/eturem/version'
|
|
3
|
-
|
|
4
|
-
Gem::Specification.new do |spec|
|
|
5
|
-
spec.name = "eturem"
|
|
6
|
-
spec.version = Eturem::VERSION
|
|
7
|
-
spec.authors = ["nodai2hITC"]
|
|
8
|
-
spec.email = ["nodai2h.itc@gmail.com"]
|
|
9
|
-
|
|
10
|
-
spec.summary = %q{Easy To Understand Ruby Error Message.}
|
|
11
|
-
spec.description = %q{Easy To Understand Ruby Error Message.}
|
|
12
|
-
spec.homepage = "https://github.com/nodai2hITC/eturem"
|
|
13
|
-
spec.license = "MIT"
|
|
14
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
|
15
|
-
|
|
16
|
-
# spec.metadata["allowed_push_host"] = "Set to 'http://mygemserver.com'"
|
|
17
|
-
|
|
18
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
|
19
|
-
spec.metadata["source_code_uri"] = spec.homepage
|
|
20
|
-
# spec.metadata["changelog_uri"] = spec.homepage
|
|
21
|
-
|
|
22
|
-
# Specify which files should be added to the gem when it is released.
|
|
23
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
24
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
25
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
26
|
-
end
|
|
27
|
-
spec.bindir = "exe"
|
|
28
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
29
|
-
spec.require_paths = ["lib"]
|
|
30
|
-
end
|
|
1
|
+
|
|
2
|
+
require_relative 'lib/eturem/version'
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |spec|
|
|
5
|
+
spec.name = "eturem"
|
|
6
|
+
spec.version = Eturem::VERSION
|
|
7
|
+
spec.authors = ["nodai2hITC"]
|
|
8
|
+
spec.email = ["nodai2h.itc@gmail.com"]
|
|
9
|
+
|
|
10
|
+
spec.summary = %q{Easy To Understand Ruby Error Message.}
|
|
11
|
+
spec.description = %q{Easy To Understand Ruby Error Message.}
|
|
12
|
+
spec.homepage = "https://github.com/nodai2hITC/eturem"
|
|
13
|
+
spec.license = "MIT"
|
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
|
15
|
+
|
|
16
|
+
# spec.metadata["allowed_push_host"] = "Set to 'http://mygemserver.com'"
|
|
17
|
+
|
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
20
|
+
# spec.metadata["changelog_uri"] = spec.homepage
|
|
21
|
+
|
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
26
|
+
end
|
|
27
|
+
spec.bindir = "exe"
|
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
29
|
+
spec.require_paths = ["lib"]
|
|
30
|
+
end
|
data/lib/eturem.rb
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
enable = true
|
|
2
|
-
debug = false
|
|
3
|
-
lang = "en"
|
|
4
|
-
output_backtrace = true
|
|
5
|
-
output_original = true
|
|
6
|
-
output_script = true
|
|
7
|
-
override_warning = true
|
|
8
|
-
use_coderay = false
|
|
9
|
-
before_line_num = 2
|
|
10
|
-
after_line_num = 2
|
|
11
|
-
repl = nil
|
|
12
|
-
|
|
13
|
-
config_file = File.exist?("./.eturem") ? "./.eturem" : File.join(Dir.home, ".eturem")
|
|
14
|
-
if File.exist?(config_file)
|
|
15
|
-
config = File.read(config_file).gsub(/#.*/, "")
|
|
16
|
-
enable = false if config.match(/^enable\s*\:\s*(?:false|off|0)/i)
|
|
17
|
-
debug = true if config.match(/^debug\s*\:\s*(?:true|on|1)/i)
|
|
18
|
-
lang = Regexp.last_match(:lang) if config.match(/^lang\s*\:\s*(?<lang>\S+)/i)
|
|
19
|
-
output_backtrace = false if config.match(/^output_backtrace\s*\:\s*(?:false|off|0)/i)
|
|
20
|
-
output_original = false if config.match( /^output_original\s*\:\s*(?:false|off|0)/i)
|
|
21
|
-
output_script = false if config.match( /^output_script\s*\:\s*(?:false|off|0)/i)
|
|
22
|
-
override_warning = false if config.match(/^override_warning\s*\:\s*(?:false|off|0)/i)
|
|
23
|
-
use_coderay = true if config.match( /^use_coderay\s*\:\s*(?:true|on|1)/i)
|
|
24
|
-
before_line_num = Regexp.last_match(:num).to_i if config.match(/^before_line_num\s*\:\s*(?<num>\d+)/i)
|
|
25
|
-
after_line_num = Regexp.last_match(:num).to_i if config.match( /^after_line_num\s*\:\s*(?<num>\d+)/i)
|
|
26
|
-
repl = Regexp.last_match(:repl).downcase if config.match(/^repl\s*\:\s*(?<repl>irb|pry)/i)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
if enable
|
|
30
|
-
require "eturem/#{lang}/main" unless defined?(Eturem)
|
|
31
|
-
require "eturem/warning" if override_warning
|
|
32
|
-
Eturem::Base.output_backtrace = output_backtrace
|
|
33
|
-
Eturem::Base.output_original = output_original
|
|
34
|
-
Eturem::Base.output_script = output_script
|
|
35
|
-
Eturem::Base.use_coderay = use_coderay
|
|
36
|
-
Eturem::Base.before_line_num = before_line_num
|
|
37
|
-
Eturem::Base.after_line_num = after_line_num
|
|
38
|
-
|
|
39
|
-
if File.exist?($PROGRAM_NAME)
|
|
40
|
-
program_file = File.open($PROGRAM_NAME, "rb")
|
|
41
|
-
script = program_file.read
|
|
42
|
-
if script.match(/^__END__\R/)
|
|
43
|
-
program_file.pos = Regexp.last_match.end(0)
|
|
44
|
-
encoding = "utf-8"
|
|
45
|
-
if script.match(/\A(?:#!.*\R)?#.*coding *[:=] *(?<encoding>[^\s:]+)/)
|
|
46
|
-
encoding = Regexp.last_match(:encoding)
|
|
47
|
-
end
|
|
48
|
-
program_file.set_encoding(encoding)
|
|
49
|
-
Object.const_set(:DATA, program_file)
|
|
50
|
-
program_file
|
|
51
|
-
else
|
|
52
|
-
program_file.close
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
eturem_path = File.expand_path("..", __FILE__)
|
|
57
|
-
last_binding = nil
|
|
58
|
-
tracepoint = TracePoint.trace(:raise) do |tp|
|
|
59
|
-
last_binding = tp.binding unless File.expand_path(tp.path).start_with?(eturem_path)
|
|
60
|
-
end
|
|
61
|
-
exception = Eturem.load(File.expand_path(Eturem.program_name))
|
|
62
|
-
tracepoint.disable
|
|
63
|
-
|
|
64
|
-
if exception.is_a?(Exception)
|
|
65
|
-
begin
|
|
66
|
-
Eturem.extend_exception(exception)
|
|
67
|
-
$stderr.write exception.eturem_full_message
|
|
68
|
-
rescue Exception => e
|
|
69
|
-
raise debug ? e : exception
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
repl ||= $eturem_repl if defined?($eturem_repl)
|
|
73
|
-
if repl && last_binding && exception.is_a?(StandardError)
|
|
74
|
-
require repl
|
|
75
|
-
last_binding.public_send(repl)
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
exit
|
|
79
|
-
end
|
|
1
|
+
enable = true
|
|
2
|
+
debug = false
|
|
3
|
+
lang = "en"
|
|
4
|
+
output_backtrace = true
|
|
5
|
+
output_original = true
|
|
6
|
+
output_script = true
|
|
7
|
+
override_warning = true
|
|
8
|
+
use_coderay = false
|
|
9
|
+
before_line_num = 2
|
|
10
|
+
after_line_num = 2
|
|
11
|
+
repl = nil
|
|
12
|
+
|
|
13
|
+
config_file = File.exist?("./.eturem") ? "./.eturem" : File.join(Dir.home, ".eturem")
|
|
14
|
+
if File.exist?(config_file)
|
|
15
|
+
config = File.read(config_file).gsub(/#.*/, "")
|
|
16
|
+
enable = false if config.match(/^enable\s*\:\s*(?:false|off|0)/i)
|
|
17
|
+
debug = true if config.match(/^debug\s*\:\s*(?:true|on|1)/i)
|
|
18
|
+
lang = Regexp.last_match(:lang) if config.match(/^lang\s*\:\s*(?<lang>\S+)/i)
|
|
19
|
+
output_backtrace = false if config.match(/^output_backtrace\s*\:\s*(?:false|off|0)/i)
|
|
20
|
+
output_original = false if config.match( /^output_original\s*\:\s*(?:false|off|0)/i)
|
|
21
|
+
output_script = false if config.match( /^output_script\s*\:\s*(?:false|off|0)/i)
|
|
22
|
+
override_warning = false if config.match(/^override_warning\s*\:\s*(?:false|off|0)/i)
|
|
23
|
+
use_coderay = true if config.match( /^use_coderay\s*\:\s*(?:true|on|1)/i)
|
|
24
|
+
before_line_num = Regexp.last_match(:num).to_i if config.match(/^before_line_num\s*\:\s*(?<num>\d+)/i)
|
|
25
|
+
after_line_num = Regexp.last_match(:num).to_i if config.match( /^after_line_num\s*\:\s*(?<num>\d+)/i)
|
|
26
|
+
repl = Regexp.last_match(:repl).downcase if config.match(/^repl\s*\:\s*(?<repl>irb|pry)/i)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
if enable
|
|
30
|
+
require "eturem/#{lang}/main" unless defined?(Eturem)
|
|
31
|
+
require "eturem/warning" if override_warning
|
|
32
|
+
Eturem::Base.output_backtrace = output_backtrace
|
|
33
|
+
Eturem::Base.output_original = output_original
|
|
34
|
+
Eturem::Base.output_script = output_script
|
|
35
|
+
Eturem::Base.use_coderay = use_coderay
|
|
36
|
+
Eturem::Base.before_line_num = before_line_num
|
|
37
|
+
Eturem::Base.after_line_num = after_line_num
|
|
38
|
+
|
|
39
|
+
if File.exist?($PROGRAM_NAME)
|
|
40
|
+
program_file = File.open($PROGRAM_NAME, "rb")
|
|
41
|
+
script = program_file.read
|
|
42
|
+
if script.match(/^__END__\R/)
|
|
43
|
+
program_file.pos = Regexp.last_match.end(0)
|
|
44
|
+
encoding = "utf-8"
|
|
45
|
+
if script.match(/\A(?:#!.*\R)?#.*coding *[:=] *(?<encoding>[^\s:]+)/)
|
|
46
|
+
encoding = Regexp.last_match(:encoding)
|
|
47
|
+
end
|
|
48
|
+
program_file.set_encoding(encoding)
|
|
49
|
+
Object.const_set(:DATA, program_file)
|
|
50
|
+
program_file
|
|
51
|
+
else
|
|
52
|
+
program_file.close
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
eturem_path = File.expand_path("..", __FILE__)
|
|
57
|
+
last_binding = nil
|
|
58
|
+
tracepoint = TracePoint.trace(:raise) do |tp|
|
|
59
|
+
last_binding = tp.binding unless File.expand_path(tp.path).start_with?(eturem_path)
|
|
60
|
+
end
|
|
61
|
+
exception = Eturem.load(File.expand_path(Eturem.program_name))
|
|
62
|
+
tracepoint.disable
|
|
63
|
+
|
|
64
|
+
if exception.is_a?(Exception)
|
|
65
|
+
begin
|
|
66
|
+
Eturem.extend_exception(exception)
|
|
67
|
+
$stderr.write exception.eturem_full_message
|
|
68
|
+
rescue Exception => e
|
|
69
|
+
raise debug ? e : exception
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
repl ||= $eturem_repl if defined?($eturem_repl)
|
|
73
|
+
if repl && last_binding && exception.is_a?(StandardError)
|
|
74
|
+
require repl
|
|
75
|
+
last_binding.public_send(repl)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
exit
|
|
79
|
+
end
|
data/lib/eturem/base.rb
CHANGED
|
@@ -118,7 +118,10 @@ module Eturem
|
|
|
118
118
|
this_dirpath = File.dirname(File.expand_path(__FILE__))
|
|
119
119
|
@eturem_backtrace_locations = (self.backtrace_locations || []).reject do |location|
|
|
120
120
|
File.expand_path(location.path).start_with?(this_dirpath) ||
|
|
121
|
-
location.path.end_with?(
|
|
121
|
+
location.path.end_with?(
|
|
122
|
+
"/rubygems/core_ext/kernel_require.rb",
|
|
123
|
+
"/rubygems/core_ext/kernel_require.rb"
|
|
124
|
+
)
|
|
122
125
|
end
|
|
123
126
|
|
|
124
127
|
program_filepath = File.expand_path(Eturem.program_name)
|
|
@@ -159,7 +162,7 @@ module Eturem
|
|
|
159
162
|
"#{Regexp.last_match.post_match.chomp}\e[0m\n"
|
|
160
163
|
end
|
|
161
164
|
|
|
162
|
-
def eturem_backtrace_str(order = :
|
|
165
|
+
def eturem_backtrace_str(order = :top)
|
|
163
166
|
str = @eturem_backtrace_locations.empty? ? "" : eturem_traceback(order)
|
|
164
167
|
str + (order == :top ? eturem_backtrace_str_top : eturem_backtrace_str_bottom)
|
|
165
168
|
end
|
|
@@ -186,11 +189,8 @@ module Eturem
|
|
|
186
189
|
Eturem::Base.script(@eturem_script_lines, @eturem_output_linenos, @eturem_lineno)
|
|
187
190
|
end
|
|
188
191
|
|
|
189
|
-
def eturem_full_message(highlight: true, order: :
|
|
190
|
-
unless $stderr == STDERR && $stderr.tty?
|
|
191
|
-
highlight = false
|
|
192
|
-
order = :top
|
|
193
|
-
end
|
|
192
|
+
def eturem_full_message(highlight: true, order: :top)
|
|
193
|
+
highlight = false unless $stderr == STDERR && $stderr.tty?
|
|
194
194
|
|
|
195
195
|
str = @@eturem_output_backtrace ? eturem_backtrace_str(order) : ""
|
|
196
196
|
ext_message = eturem_message
|
data/lib/eturem/version.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module Eturem
|
|
2
|
-
VERSION = "0.5.
|
|
3
|
-
end
|
|
1
|
+
module Eturem
|
|
2
|
+
VERSION = "0.5.3"
|
|
3
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: eturem
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- nodai2hITC
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-04-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Easy To Understand Ruby Error Message.
|
|
14
14
|
email:
|
|
@@ -57,7 +57,7 @@ licenses:
|
|
|
57
57
|
metadata:
|
|
58
58
|
homepage_uri: https://github.com/nodai2hITC/eturem
|
|
59
59
|
source_code_uri: https://github.com/nodai2hITC/eturem
|
|
60
|
-
post_install_message:
|
|
60
|
+
post_install_message:
|
|
61
61
|
rdoc_options: []
|
|
62
62
|
require_paths:
|
|
63
63
|
- lib
|
|
@@ -72,8 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
72
72
|
- !ruby/object:Gem::Version
|
|
73
73
|
version: '0'
|
|
74
74
|
requirements: []
|
|
75
|
-
rubygems_version: 3.
|
|
76
|
-
signing_key:
|
|
75
|
+
rubygems_version: 3.2.3
|
|
76
|
+
signing_key:
|
|
77
77
|
specification_version: 4
|
|
78
78
|
summary: Easy To Understand Ruby Error Message.
|
|
79
79
|
test_files: []
|