Exception: Sass::SyntaxError

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

Overview

Sass::SyntaxError encapsulates information about the exception, such as the line of the Sass template it was raised on and the Sass file that was being parsed (if applicable). It also provides a handy way to rescue only exceptions raised because of a faulty template.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg, lineno = nil) ⇒ SyntaxError

Creates a new SyntaxError. lineno should be the line of the Sass template on which the error occurred.



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

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

Instance Attribute Details

#sass_filenameObject (readonly)

The name of the file that was being parsed when the exception was raised. This will be nil unless Sass is being used as an ActionView plugin.



13
14
15
# File 'lib/sass/error.rb', line 13

def sass_filename
  @sass_filename
end

#sass_lineObject

The line of the Sass template on which the exception was thrown.



9
10
11
# File 'lib/sass/error.rb', line 9

def sass_line
  @sass_line
end

Instance Method Details

#add_backtrace_entry(filename) ⇒ Object

Adds a properly formatted entry to the exception’s backtrace. filename should be the file in which the error occurred, if applicable (defaults to “(sass)”).



25
26
27
28
29
# File 'lib/sass/error.rb', line 25

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

#to_sObject

:nodoc:



31
32
33
# File 'lib/sass/error.rb', line 31

def to_s # :nodoc:
  @message
end