1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Sass] Print the Sass backtrace on error for the sass executable.

This commit is contained in:
Nathan Weizenbaum 2009-09-13 16:20:20 -07:00
parent 616a00cea6
commit f4380e655a
3 changed files with 21 additions and 1 deletions

View file

@ -12,6 +12,10 @@ especially when importing files.
All imports will now show up in the Ruby backtrace,
with the proper filename and line number.
In addition, when the `sass` executable encounters an error,
it now prints the filename where the error occurs,
as well as a backtrace of Sass imports.
## [2.2.3](http://github.com/nex3/haml/commit/2.2.3)
Sass 2.2.3 prints line numbers for warnings about selectors

View file

@ -264,7 +264,7 @@ END
output.close() if output.is_a? File
rescue ::Sass::SyntaxError => e
raise e if @options[:trace]
raise "Syntax error on line #{get_line e}: #{e.message}"
raise e.sass_backtrace_str("standard input")
end
end

View file

@ -96,6 +96,22 @@ module Sass
return nil if super.nil?
sass_backtrace.map {|h| "#{h[:filename] || "(sass)"}:#{h[:line]}"} + super
end
# Returns a string representation of the Sass backtrace.
#
# @param default_filename [String] The filename to use for unknown files
# @see #sass_backtrace
# @return [String]
def sass_backtrace_str(default_filename = "an unknown file")
msg = "Syntax error on line #{sass_line}" +
" of #{sass_filename || default_filename}" +
": #{message}"
sass_backtrace[1..-1].each do |entry|
msg << "\n from line #{entry[:line]}" +
" of #{entry[:filename] || default_filename}"
end
msg
end
end
# The class for Sass errors that are raised due to invalid unit conversions