File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -11,17 +11,19 @@ class UnsupportedValue < BaseError; end
11
11
# it's important to provide filename and line number information.
12
12
# This will be used in various error reports to users, including backtraces;
13
13
class SyntaxError < BaseError
14
+ LINE_INFO_REGEX = /on line (\d +) of (.+)/
15
+
14
16
def backtrace
15
17
return nil if super . nil?
16
18
sass_backtrace + super
17
19
end
18
20
19
21
# The backtrace of the error within Sass files.
20
22
def sass_backtrace
21
- line_info = message . split ( "\n " ) [ 1 ]
23
+ line_info = message . split ( "\n " ) . find { | line | line . match ( LINE_INFO_REGEX ) }
22
24
return [ ] unless line_info
23
25
24
- _ , line , filename = line_info . match ( /on line ( \d +) of (.+)/ ) . to_a
26
+ _ , line , filename = line_info . match ( LINE_INFO_REGEX ) . to_a
25
27
[ "#{ Pathname . getwd . join ( filename ) } :#{ line } " ]
26
28
end
27
29
end
Original file line number Diff line number Diff line change @@ -17,6 +17,21 @@ def test_first_backtrace_is_sass
17
17
expected = "#{ Pathname . getwd . join ( filename ) } :#{ line } "
18
18
assert_equal expected , err . backtrace . first
19
19
end
20
+
21
+ begin
22
+ raise SassC ::SyntaxError . new ( <<-ERROR )
23
+ Error: no mixin named border-radius
24
+
25
+ Backtrace:
26
+ \t #{ filename } :#{ line }
27
+ on line #{ line } of #{ filename }
28
+ >> @include border-radius(5px);
29
+ -------------^
30
+ ERROR
31
+ rescue SassC ::SyntaxError => err
32
+ expected = "#{ Pathname . getwd . join ( filename ) } :#{ line } "
33
+ assert_equal expected , err . backtrace . first
34
+ end
20
35
end
21
36
end
22
37
end
You can’t perform that action at this time.
0 commit comments