Exception: Sass::SyntaxError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/sass/error.rb

Overview

An exception class that keeps track of the line of the Sass template it was raised on and the Sass file that was being parsed (if applicable).

All Sass errors are raised as SyntaxErrors.

Direct Known Subclasses

UnitConversionError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg, lineno = nil) ⇒ SyntaxError

Returns a new instance of SyntaxError.

Parameters:

  • msg (String)

    The error message

  • lineno (Fixnum) (defaults to: nil)


21
22
23
24
# File 'lib/sass/error.rb', line 21

def initialize(msg, lineno = nil)
  @message = msg
  @sass_line = lineno
end

Instance Attribute Details

#sass_filenameString (readonly)

The name of the file that was being parsed when the exception was raised. This could be nil if no filename is available.

Returns:

  • (String)


17
18
19
# File 'lib/sass/error.rb', line 17

def sass_filename
  @sass_filename
end

#sass_lineFixnum

The line of the Sass template on which the error occurred.

Returns:

  • (Fixnum)


11
12
13
# File 'lib/sass/error.rb', line 11

def sass_line
  @sass_line
end

Instance Method Details

#add_backtrace_entry(filename) ⇒ Object

Adds a properly formatted entry to the exception's backtrace.

Parameters:

  • filename (String)

    The file in which the error occurred, if applicable (defaults to "(sass)")



42
43
44
45
46
# File 'lib/sass/error.rb', line 42

def add_backtrace_entry(filename) # :nodoc:
  @sass_filename ||= filename
  self.backtrace ||= []
  self.backtrace.unshift "#{@sass_filename || '(sass)'}:#{@sass_line}"
end

#add_metadata(filename, line) ⇒ Object

Add information about the filename and line on which the error was raised, and re-raises the exception.

Parameters:

Raises:



32
33
34
35
36
# File 'lib/sass/error.rb', line 32

def add_metadata(filename, line)
  self.sass_line ||= line
  add_backtrace_entry(filename) unless sass_filename
  raise self
end

#to_sString

Returns The error message.

Returns:

  • (String)

    The error message



49
50
51
# File 'lib/sass/error.rb', line 49

def to_s
  @message
end