2007-01-28 10:14:15 +00:00
|
|
|
module Sass
|
2009-04-24 23:45:46 -07:00
|
|
|
# An exception class that keeps track of
|
|
|
|
# the line of the Sass template it was raised on
|
2007-01-28 10:14:15 +00:00
|
|
|
# and the Sass file that was being parsed (if applicable).
|
2009-04-24 23:45:46 -07:00
|
|
|
#
|
|
|
|
# All Sass errors are raised as {Sass::SyntaxError}s.
|
2008-08-29 20:40:42 -07:00
|
|
|
class SyntaxError < StandardError
|
2009-04-24 23:45:46 -07:00
|
|
|
# The line of the Sass template on which the error occurred.
|
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
2007-01-28 17:24:08 +00:00
|
|
|
attr_accessor :sass_line
|
2007-01-28 10:14:15 +00:00
|
|
|
|
|
|
|
# The name of the file that was being parsed when the exception was raised.
|
2009-04-24 23:45:46 -07:00
|
|
|
# This could be `nil` if no filename is available.
|
|
|
|
#
|
|
|
|
# @return [String]
|
2007-01-28 10:14:15 +00:00
|
|
|
attr_reader :sass_filename
|
|
|
|
|
2009-04-24 23:45:46 -07:00
|
|
|
# @param msg [String] The error message
|
|
|
|
# @param lineno [Fixnum] See \{#sass\_line}
|
2007-01-28 17:24:08 +00:00
|
|
|
def initialize(msg, lineno = nil)
|
2007-02-04 03:20:24 +00:00
|
|
|
@message = msg
|
2007-01-28 10:14:15 +00:00
|
|
|
@sass_line = lineno
|
|
|
|
end
|
|
|
|
|
2009-04-25 12:52:46 -07:00
|
|
|
# Add information about the filename and line on which the error was raised,
|
|
|
|
# and re-raises the exception.
|
|
|
|
#
|
|
|
|
# @param filename [String] See \{#sass\_filename}
|
|
|
|
# @param line [Fixnum] See \{#sass\_line}
|
|
|
|
# @raise [Sass::SyntaxError] self
|
2009-04-21 19:13:05 -07:00
|
|
|
def add_metadata(filename, line)
|
|
|
|
self.sass_line ||= line
|
|
|
|
add_backtrace_entry(filename) unless sass_filename
|
|
|
|
raise self
|
|
|
|
end
|
|
|
|
|
2007-01-28 10:14:15 +00:00
|
|
|
# Adds a properly formatted entry to the exception's backtrace.
|
2009-04-24 23:45:46 -07:00
|
|
|
#
|
|
|
|
# @param filename [String] The file in which the error occurred,
|
|
|
|
# if applicable (defaults to "(sass)")
|
2007-02-02 06:15:28 +00:00
|
|
|
def add_backtrace_entry(filename) # :nodoc:
|
2007-03-25 04:57:03 +00:00
|
|
|
@sass_filename ||= filename
|
2007-01-28 10:14:15 +00:00
|
|
|
self.backtrace ||= []
|
2007-03-25 04:57:03 +00:00
|
|
|
self.backtrace.unshift "#{@sass_filename || '(sass)'}:#{@sass_line}"
|
2007-01-28 10:14:15 +00:00
|
|
|
end
|
2007-02-04 03:20:24 +00:00
|
|
|
|
2009-04-24 23:45:46 -07:00
|
|
|
# @return [String] The error message
|
|
|
|
def to_s
|
2007-02-04 03:20:24 +00:00
|
|
|
@message
|
|
|
|
end
|
2007-01-28 10:14:15 +00:00
|
|
|
end
|
2009-07-03 14:11:56 -07:00
|
|
|
|
2009-07-04 14:19:07 -07:00
|
|
|
# The class for Sass errors that are raised due to invalid unit conversions
|
|
|
|
# in SassScript.
|
|
|
|
class UnitConversionError < SyntaxError; end
|
2007-01-28 10:14:15 +00:00
|
|
|
end
|