File tree Expand file tree Collapse file tree 3 files changed +23
-29
lines changed Expand file tree Collapse file tree 3 files changed +23
-29
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,10 @@ def render
40
40
41
41
if status != 0
42
42
message = Native . context_get_error_message ( context )
43
- raise SyntaxError . new ( message )
43
+ filename = Native . context_get_error_file ( context )
44
+ line = Native . context_get_error_line ( context )
45
+
46
+ raise SyntaxError . new ( message , filename : filename , line : line )
44
47
end
45
48
46
49
css = Native . context_get_output_string ( context )
Original file line number Diff line number Diff line change @@ -11,7 +11,11 @@ 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 (.+)/
14
+ def initialize ( message , filename : nil , line : nil )
15
+ @filename = filename
16
+ @line = line
17
+ super ( message )
18
+ end
15
19
16
20
def backtrace
17
21
return nil if super . nil?
@@ -20,11 +24,8 @@ def backtrace
20
24
21
25
# The backtrace of the error within Sass files.
22
26
def sass_backtrace
23
- line_info = message . split ( "\n " ) . find { |line | line . match ( LINE_INFO_REGEX ) }
24
- return [ ] unless line_info
25
-
26
- _ , line , filename = line_info . match ( LINE_INFO_REGEX ) . to_a
27
- [ "#{ Pathname . getwd . join ( filename ) } :#{ line } " ]
27
+ return [ ] unless @filename && @line
28
+ [ "#{ @filename } :#{ @line } " ]
28
29
end
29
30
end
30
31
end
Original file line number Diff line number Diff line change 2
2
3
3
module SassC
4
4
class ErrorTest < MiniTest ::Test
5
+ def render ( data , opts = { } )
6
+ Engine . new ( data , opts ) . render
7
+ end
8
+
5
9
def test_first_backtrace_is_sass
6
- line = 2
7
10
filename = "app/assets/stylesheets/application.scss"
8
11
9
12
begin
10
- raise SassC ::SyntaxError . new ( <<-ERROR )
11
- Error: property "padding" must be followed by a ':'
12
- on line #{ line } of #{ filename }
13
- >> padding top: 10px;
14
- --^
15
- ERROR
16
- rescue SassC ::SyntaxError => err
17
- expected = "#{ Pathname . getwd . join ( filename ) } :#{ line } "
18
- assert_equal expected , err . backtrace . first
19
- end
20
-
21
- begin
22
- raise SassC ::SyntaxError . new ( <<-ERROR )
23
- Error: no mixin named border-radius
13
+ template = <<-SCSS
14
+ .foo {
15
+ baz: bang;
16
+ padding top: 10px;
17
+ }
18
+ SCSS
24
19
25
- Backtrace:
26
- \t #{ filename } :#{ line }
27
- on line #{ line } of #{ filename }
28
- >> @include border-radius(5px);
29
- -------------^
30
- ERROR
20
+ render ( template , filename : filename )
31
21
rescue SassC ::SyntaxError => err
32
- expected = "#{ Pathname . getwd . join ( filename ) } : #{ line } "
22
+ expected = "#{ filename } :3 "
33
23
assert_equal expected , err . backtrace . first
34
24
end
35
25
end
You can’t perform that action at this time.
0 commit comments