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

[Sass] Only display text on the current line when reporting css2sass errors.

This commit is contained in:
Nathan Weizenbaum 2009-09-23 14:45:14 -07:00
parent de8e5a0776
commit 0e68e5fcf5
3 changed files with 28 additions and 8 deletions

View file

@ -16,10 +16,14 @@ 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.
### Minor Changes
### `css2sass` Error Handling
* `css2sass` error handling and reporting has been improved,
including fixing line-number reporting for templates without trailing newlines.
Several bug fixes and minor improvements have been made, including:
* Fixing line-number reporting for errors on the last line of templates
that didn't have trailing newlines.
* Only displaying the text for the current line when reporting CSS parsing errors.
## [2.2.4](http://github.com/nex3/haml/commit/2.2.4)

View file

@ -201,13 +201,13 @@ module Sass
pos = @template.pos
after = @template.string[pos - 15...pos]
after = @template.string[[pos - 15, 0].max...pos].gsub(/.*\n/m, '')
after = "..." + after if pos >= 15
# Display basic regexps as plain old strings
expected = re.source == Regexp.escape(re.source) ? "\"#{re.source}\"" : re.inspect
was = @template.rest[0...15]
was = @template.rest[0...15].gsub(/\n.*/m, '')
was += "..." if @template.rest.size >= 15
raise Sass::SyntaxError.new(
"Invalid CSS after #{after.inspect}: expected #{expected}, was #{was.inspect}")

View file

@ -235,15 +235,31 @@ CSS
assert(false, "Expected exception")
rescue Sass::SyntaxError => err
assert_equal(1, err.sass_line)
assert_equal('Invalid CSS after nil: expected /\{/, was ""', err.message)
assert_equal('Invalid CSS after "foo": expected /\{/, was ""', err.message)
end
def test_error_reporting_in_line
css2sass("foo\nbar }")
css2sass("foo\nbar }\nbaz")
assert(false, "Expected exception")
rescue Sass::SyntaxError => err
assert_equal(2, err.sass_line)
assert_equal('Invalid CSS after "o\nbar ": expected /\{/, was "}"', err.message)
assert_equal('Invalid CSS after "bar ": expected /\{/, was "}"', err.message)
end
def test_error_truncate_after
css2sass("#{"a" * 15}foo")
assert(false, "Expected exception")
rescue Sass::SyntaxError => err
assert_equal(1, err.sass_line)
assert_equal('Invalid CSS after "...aaaaaaaaaaaafoo": expected /\{/, was ""', err.message)
end
def test_error_truncate_was
css2sass("foo }#{"a" * 15}")
assert(false, "Expected exception")
rescue Sass::SyntaxError => err
assert_equal(1, err.sass_line)
assert_equal('Invalid CSS after "foo ": expected /\{/, was "}aaaaaaaaaaaaaa..."', err.message)
end
private