File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change
1
+ require 'pathname'
1
2
require 'sass/error'
2
3
3
4
module SassC
4
5
class BaseError < StandardError ; end
5
- class SyntaxError < BaseError ; end
6
6
class NotRenderedError < BaseError ; end
7
7
class InvalidStyleError < BaseError ; end
8
8
class UnsupportedValue < BaseError ; end
9
+
10
+ # When dealing with SyntaxErrors,
11
+ # it's important to provide filename and line number information.
12
+ # This will be used in various error reports to users, including backtraces;
13
+ class SyntaxError < BaseError
14
+ def backtrace
15
+ return nil if super . nil?
16
+ sass_backtrace + super
17
+ end
18
+
19
+ # The backtrace of the error within Sass files.
20
+ def sass_backtrace
21
+ line_info = message . split ( "\n " ) [ 1 ]
22
+ return [ ] unless line_info
23
+
24
+ _ , line , filename = line_info . match ( /on line (\d +) of (.+)/ ) . to_a
25
+ [ "#{ Pathname . getwd . join ( filename ) } :#{ line } " ]
26
+ end
27
+ end
9
28
end
Original file line number Diff line number Diff line change
1
+ require_relative "test_helper"
2
+
3
+ module SassC
4
+ class ErrorTest < MiniTest ::Test
5
+ def test_first_backtrace_is_sass
6
+ line = 2
7
+ filename = "app/assets/stylesheets/application.scss"
8
+
9
+ 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
+ end
21
+ end
22
+ end
You can’t perform that action at this time.
0 commit comments