Nicer error formatting, correct line numbering on errors thrown.
git-svn-id: svn://hamptoncatlin.com/haml/trunk@334 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
6f636eb5b8
commit
bbc8dc9582
|
@ -30,7 +30,7 @@ module Sass
|
||||||
#
|
#
|
||||||
#--
|
#--
|
||||||
#
|
#
|
||||||
# TODO: Add current options to REFRENCE.
|
# TODO: Add current options to REFRENCE. Remember :filename!
|
||||||
#
|
#
|
||||||
# When adding options, remember to add information about them
|
# When adding options, remember to add information about them
|
||||||
# to README!
|
# to README!
|
||||||
|
@ -59,7 +59,7 @@ module Sass
|
||||||
|
|
||||||
root.to_s
|
root.to_s
|
||||||
rescue SyntaxError => err
|
rescue SyntaxError => err
|
||||||
err.add_backtrace_entry
|
err.add_backtrace_entry(@options[:filename])
|
||||||
raise err
|
raise err
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -109,7 +109,7 @@ module Sass
|
||||||
def build_tree(index)
|
def build_tree(index)
|
||||||
line, tabs = @lines[index]
|
line, tabs = @lines[index]
|
||||||
index += 1
|
index += 1
|
||||||
@line = index + 1
|
@line = index
|
||||||
node = parse_line(line)
|
node = parse_line(line)
|
||||||
|
|
||||||
# Node is nil if it's non-outputting, like a constant assignment
|
# Node is nil if it's non-outputting, like a constant assignment
|
||||||
|
@ -119,7 +119,7 @@ module Sass
|
||||||
|
|
||||||
while has_children
|
while has_children
|
||||||
child, index = build_tree(index)
|
child, index = build_tree(index)
|
||||||
child.line = index
|
child.line = @line
|
||||||
node << child if child
|
node << child if child
|
||||||
has_children = has_children?(index, tabs)
|
has_children = has_children?(index, tabs)
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,7 +22,7 @@ module Sass
|
||||||
# Adds a properly formatted entry to the exception's backtrace.
|
# Adds a properly formatted entry to the exception's backtrace.
|
||||||
# +filename+ should be the file in which the error occurred,
|
# +filename+ should be the file in which the error occurred,
|
||||||
# if applicable (defaults to "(sass)").
|
# if applicable (defaults to "(sass)").
|
||||||
def add_backtrace_entry(filename = nil) # :nodoc:
|
def add_backtrace_entry(filename) # :nodoc:
|
||||||
@sass_filename = filename
|
@sass_filename = filename
|
||||||
self.backtrace ||= []
|
self.backtrace ||= []
|
||||||
self.backtrace.unshift "#{filename || '(sass)'}:#{@sass_line}"
|
self.backtrace.unshift "#{filename || '(sass)'}:#{@sass_line}"
|
||||||
|
|
|
@ -45,14 +45,37 @@ module Sass
|
||||||
css = css_filename(name)
|
css = css_filename(name)
|
||||||
File.delete(css) if File.exists?(css)
|
File.delete(css) if File.exists?(css)
|
||||||
|
|
||||||
engine = Engine.new(File.read(template_filename(name)), @@options.dup)
|
filename = template_filename(name)
|
||||||
|
options = @@options.dup
|
||||||
|
options[:filename] = filename
|
||||||
|
engine = Engine.new(File.read(filename), options)
|
||||||
begin
|
begin
|
||||||
result = engine.render
|
result = engine.render
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
if RAILS_ENV != "production"
|
if RAILS_ENV != "production"
|
||||||
result = "#{e}\n\nBacktrace:\n#{e.backtrace.join("\n")}\n"
|
e_string = "#{e.class}: #{e.message}"
|
||||||
|
|
||||||
|
if e.is_a? Sass::SyntaxError
|
||||||
|
e_string << "\non line #{e.sass_line}"
|
||||||
|
|
||||||
|
if e.sass_filename
|
||||||
|
e_string << " of #{e.sass_filename}"
|
||||||
|
|
||||||
|
if File.exists?(e.sass_filename)
|
||||||
|
e_string << "\n\n"
|
||||||
|
|
||||||
|
min = [e.sass_line - 5, 0].max
|
||||||
|
File.read(e.sass_filename).rstrip.split("\n")[
|
||||||
|
min .. e.sass_line + 5
|
||||||
|
].each_with_index do |line, i|
|
||||||
|
e_string << "#{min + i + 1}: #{line}\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
result = "/*\n#{e_string}\n\nBacktrace:\n#{e.backtrace.join("\n")}\n*/"
|
||||||
else
|
else
|
||||||
raise e
|
result = "/* Internal stylesheet error */"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -37,19 +37,9 @@ class SassPluginTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_exception_handling
|
def test_exception_handling
|
||||||
File.open(tempfile_loc('bork')) do |file|
|
File.open(tempfile_loc('bork')) do |file|
|
||||||
assert_equal("Undefined constant: \"!bork\"", file.gets.strip)
|
assert_equal("/*\nSass::SyntaxError: Undefined constant: \"!bork\"\non line 2 of #{File.dirname(__FILE__) + '/templates/bork.sass'}\n\n1: bork\n2: :bork= !bork", file.read.split("\n")[0...6].join("\n"))
|
||||||
end
|
end
|
||||||
File.delete(tempfile_loc('bork'))
|
File.delete(tempfile_loc('bork'))
|
||||||
Sass.const_set('RAILS_ENV', 'production')
|
|
||||||
raised = false
|
|
||||||
begin
|
|
||||||
Sass::Plugin.update_stylesheets
|
|
||||||
rescue
|
|
||||||
raised = true
|
|
||||||
end
|
|
||||||
assert raised
|
|
||||||
assert !File.exists?(tempfile_loc('bork'))
|
|
||||||
Sass::Plugin.const_set('RAILS_ENV', 'testing')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_controller_process
|
def test_controller_process
|
||||||
|
|
Loading…
Reference in New Issue