class Sass::SyntaxError

with the information filled in.
When doing this, be sure that all exceptions ultimately end up
and then calling {#modify_backtrace} in a wrapper ‘rescue`.
by omitting the information on the original exception,
In those situations, the default values can be used
It may also be useful to have a default line number set.
the same filename or even line.
Often, a chunk of code will all have similar backtrace information -
which is called when an exception is raised between files (e.g. with `@import`).
New backtrace entries can be added with {#add_backtrace},
Some of this information is usually provided as part of the constructor.
see {#sass_backtrace} for details.
This will be used in various error reports to users, including backtraces;
it’s important to provide filename and line number information.
When dealing with SyntaxErrors,
All Sass errors are raised as {Sass::SyntaxError}s.
and the Sass file that was being parsed (if applicable).
the line of the Sass template it was raised on
An exception class that keeps track of

def add_backtrace(attrs)

Parameters:
  • attrs ({Symbol => Object}) -- The information in the backtrace entry.
def add_backtrace(attrs)
  sass_backtrace << attrs.reject {|k, v| v.nil?}
end

def backtrace

Returns:
  • (Array) -
def backtrace
  return nil if super.nil?
  sass_backtrace.map do |h|
    "#{h[:filename] || "(sass)"}:#{h[:line]}" +
      (h[:mixin] ? ":in `#{h[:mixin]}'" : "")
  end + super
end

def exception_to_css(e, options)

Raises:
  • (Exception) - `e`, if the

Returns:
  • (String) - The error report

Parameters:
  • options ({Symbol => Object}) -- The options passed to {Sass::Engine#initialize}
  • e (Exception) --
def exception_to_css(e, options)
  raise e unless options[:full_exception]
  header = header_string(e, options)
  <<END
er}
ace:\n#{e.backtrace.join("\n")}
efore {
e-space: pre;
-family: monospace;
ent: "#{header.gsub('"', '\"').gsub("\n", '\\A ')}"; }
end

def header_string(e, options)

def header_string(e, options)
  return "#{e.class}: #{e.message}" unless e.is_a? Sass::SyntaxError
  line_offset = options[:line] || 1
  line_num = e.sass_line + 1 - line_offset
  min = [line_num - 6, 0].max
  section = e.sass_template.rstrip.split("\n")[min ... line_num + 5]
  return e.sass_backtrace_str if section.nil? || section.empty?
  e.sass_backtrace_str + "\n\n" + Haml::Util.enum_with_index(section).
    map {|line, i| "#{line_offset + min + i}: #{line}"}.join("\n")
end

def initialize(msg, attrs = {})

Parameters:
  • attrs ({Symbol => Object}) -- The information in the backtrace entry.
  • msg (String) -- The error message
def initialize(msg, attrs = {})
  @message = msg
  @sass_backtrace = []
  add_backtrace(attrs)
end

def modify_backtrace(attrs)

Parameters:
  • attrs ({Symbol => Object}) -- The information to add to the backtrace entry.
def modify_backtrace(attrs)
  attrs = attrs.reject {|k, v| v.nil?}
  # Move backwards through the backtrace
  (0...sass_backtrace.size).to_a.reverse.each do |i|
    entry = sass_backtrace[i]
    sass_backtrace[i] = attrs.merge(entry)
    attrs.reject! {|k, v| entry.include?(k)}
    break if attrs.empty?
  end
end

def sass_backtrace_str(default_filename = "an unknown file")

Returns:
  • (String) -

Other tags:
    See: #sass_backtrace -

Parameters:
  • default_filename (String) -- The filename to use for unknown files
def sass_backtrace_str(default_filename = "an unknown file")
  lines = self.message.split("\n")
  msg = lines[0] + lines[1..-1].
    map {|l| "\n" + (" " * "Syntax error: ".size) + l}.join
  "Syntax error: #{msg}" +
    Haml::Util.enum_with_index(sass_backtrace).map do |entry, i|
    "\n        #{i == 0 ? "on" : "from"} line #{entry[:line]}" +
      " of #{entry[:filename] || default_filename}" +
      (entry[:mixin] ? ", in `#{entry[:mixin]}'" : "")
  end.join
end

def sass_filename

Returns:
  • (String, nil) -
def sass_filename
  sass_backtrace.first[:filename]
end

def sass_line

Returns:
  • (Fixnum) -
def sass_line
  sass_backtrace.first[:line]
end

def sass_mixin

Returns:
  • (Fixnum) -
def sass_mixin
  sass_backtrace.first[:mixin]
end

def to_s

Returns:
  • (String) - The error message
def to_s
  @message
end