dsl_evaluator 0.1.1 → 0.1.2
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 +1 -0
- data/CHANGELOG.md +3 -0
- data/dsl_evaluator.gemspec +2 -0
- data/lib/dsl_evaluator.rb +4 -27
- data/lib/dsl_evaluator/printer.rb +61 -0
- data/lib/dsl_evaluator/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38416a5462223f8c1b87c303e81c02d7410e76c371fde03eb03de37a9f455a90
|
4
|
+
data.tar.gz: 264bb6cc47c4c02a047dea7812810b741be48eca5f6298bce98510a568b3be26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76d9c1b745ce57961e5d8458e0037c16709617e821f43ce6ee6b4072b54cae60e117ea6a9540ee1fde97fca86276b7498a184a77fefc5cab9b8a603103e80042
|
7
|
+
data.tar.gz: bc0e3ec881d84a2ef80b16b05dbbed1c3f63877a394e9027bb409372501a557af5c08b352631ece2d49e262cde1733f7b69637bb2ca1fefce29291626501b84c
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
|
5
5
|
|
6
|
+
## [0.1.2]
|
7
|
+
- #1 get line info from error message also
|
8
|
+
|
6
9
|
## [0.1.1]
|
7
10
|
- make module methods availables
|
8
11
|
|
data/dsl_evaluator.gemspec
CHANGED
data/lib/dsl_evaluator.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
require "dsl_evaluator/version"
|
2
|
+
require "rainbow/ext/string"
|
2
3
|
|
3
4
|
module DslEvaluator
|
5
|
+
autoload :Printer, "dsl_evaluator/printer"
|
6
|
+
|
4
7
|
class Error < StandardError; end
|
5
8
|
|
6
9
|
def evaluate_file(path)
|
7
10
|
return unless path && File.file?(path)
|
8
11
|
instance_eval(IO.read(path), path)
|
9
12
|
rescue Exception => e
|
10
|
-
|
13
|
+
Printer.new(e).print
|
11
14
|
puts "\nFull error:"
|
12
15
|
raise
|
13
16
|
end
|
@@ -21,31 +24,5 @@ module DslEvaluator
|
|
21
24
|
@@backtrace_reject = v
|
22
25
|
end
|
23
26
|
|
24
|
-
# Prints out a user friendly task_definition error message
|
25
|
-
def evaluation_error(e)
|
26
|
-
lines = e.backtrace
|
27
|
-
lines = lines.reject { |l| l.include?(backtrace_reject) } if backtrace_reject
|
28
|
-
error_info = lines.first
|
29
|
-
path, line_no, _ = error_info.split(':')
|
30
|
-
line_no = line_no.to_i
|
31
|
-
puts "Error evaluating #{path}:".color(:red)
|
32
|
-
puts e.message
|
33
|
-
puts "Here's the line in #{path} with the error:\n\n"
|
34
|
-
|
35
|
-
contents = IO.read(path)
|
36
|
-
content_lines = contents.split("\n")
|
37
|
-
context = 5 # lines of context
|
38
|
-
top, bottom = [line_no-context-1, 0].max, line_no+context-1
|
39
|
-
spacing = content_lines.size.to_s.size
|
40
|
-
content_lines[top..bottom].each_with_index do |line_content, index|
|
41
|
-
line_number = top+index+1
|
42
|
-
if line_number == line_no
|
43
|
-
printf("%#{spacing}d %s\n".color(:red), line_number, line_content)
|
44
|
-
else
|
45
|
-
printf("%#{spacing}d %s\n", line_number, line_content)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
27
|
extend self
|
51
28
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module DslEvaluator
|
2
|
+
class Printer
|
3
|
+
def initialize(error)
|
4
|
+
@error = error
|
5
|
+
end
|
6
|
+
|
7
|
+
def message
|
8
|
+
@error.message
|
9
|
+
end
|
10
|
+
|
11
|
+
# Prints out a user friendly task_definition error message
|
12
|
+
def print
|
13
|
+
print_source(info)
|
14
|
+
end
|
15
|
+
|
16
|
+
def info
|
17
|
+
@error.message.include?("syntax") ? info_from_message : info_from_backtrace
|
18
|
+
end
|
19
|
+
|
20
|
+
def info_from_message
|
21
|
+
error_info = @error.message
|
22
|
+
path, line_number, _ = error_info.split(':')
|
23
|
+
{path: path, line_number: line_number}
|
24
|
+
end
|
25
|
+
|
26
|
+
def info_from_backtrace
|
27
|
+
lines = @error.backtrace
|
28
|
+
|
29
|
+
backtrace_reject = DslEvaluator.backtrace_reject
|
30
|
+
lines = lines.reject { |l| l.include?(backtrace_reject) } if backtrace_reject
|
31
|
+
lines = lines.reject { |l| l.include?("lib/dsl_evaluator") } # ignore internal lib/dsl_evaluator backtrace lines
|
32
|
+
|
33
|
+
error_info = lines.first
|
34
|
+
path, line_number, _ = error_info.split(':')
|
35
|
+
{path: path, line_number: line_number}
|
36
|
+
end
|
37
|
+
|
38
|
+
def print_source(info={})
|
39
|
+
path = info[:path]
|
40
|
+
line_number = info[:line_number].to_i
|
41
|
+
|
42
|
+
puts "Error evaluating #{path}:".color(:red)
|
43
|
+
puts @error.message
|
44
|
+
puts "Here's the line in #{path} with the error:\n\n"
|
45
|
+
|
46
|
+
contents = IO.read(path)
|
47
|
+
content_lines = contents.split("\n")
|
48
|
+
context = 5 # lines of context
|
49
|
+
top, bottom = [line_number-context-1, 0].max, line_number+context-1
|
50
|
+
lpad = content_lines.size.to_s.size
|
51
|
+
content_lines[top..bottom].each_with_index do |line_content, index|
|
52
|
+
current_line = top+index+1
|
53
|
+
if current_line == line_number
|
54
|
+
printf("%#{lpad}d %s\n".color(:red), line_number, line_content)
|
55
|
+
else
|
56
|
+
printf("%#{lpad}d %s\n", line_number, line_content)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dsl_evaluator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
12
|
-
dependencies:
|
11
|
+
date: 2020-05-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rainbow
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description:
|
14
28
|
email:
|
15
29
|
- tongueroo@gmail.com
|
@@ -29,6 +43,7 @@ files:
|
|
29
43
|
- bin/setup
|
30
44
|
- dsl_evaluator.gemspec
|
31
45
|
- lib/dsl_evaluator.rb
|
46
|
+
- lib/dsl_evaluator/printer.rb
|
32
47
|
- lib/dsl_evaluator/version.rb
|
33
48
|
homepage: https://github.com/tongueroo/dsl_evaluator
|
34
49
|
licenses:
|