diff --git a/doc-src/SASS_CHANGELOG.md b/doc-src/SASS_CHANGELOG.md index 8eb5d11e..524a26e1 100644 --- a/doc-src/SASS_CHANGELOG.md +++ b/doc-src/SASS_CHANGELOG.md @@ -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 diff --git a/lib/haml/exec.rb b/lib/haml/exec.rb index f6c07be0..f9f75d93 100644 --- a/lib/haml/exec.rb +++ b/lib/haml/exec.rb @@ -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 diff --git a/lib/sass/error.rb b/lib/sass/error.rb index 12883ba3..9b9c5f5b 100644 --- a/lib/sass/error.rb +++ b/lib/sass/error.rb @@ -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