Exception: Cataract::ParseError

Inherits:
Error
  • Object
show all
Defined in:
lib/cataract/error.rb,
ext/cataract/cataract.c

Overview

Error raised when invalid CSS is encountered in strict mode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, css: nil, pos: nil, line: nil, column: nil, type: nil) ⇒ ParseError

Returns a new instance of ParseError.

Parameters:

  • message (String)

    Error message (without position info)

  • css (String, nil) (defaults to: nil)

    Full CSS string for calculating position

  • pos (Integer, nil) (defaults to: nil)

    Byte position in CSS where error occurred

  • line (Integer, nil) (defaults to: nil)

    Line number (if already calculated)

  • column (Integer, nil) (defaults to: nil)

    Column number (if already calculated)

  • type (Symbol, nil) (defaults to: nil)

    Type of parse error (:empty_value, :malformed_declaration, etc.)



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cataract/error.rb', line 24

def initialize(message, css: nil, pos: nil, line: nil, column: nil, type: nil)
  # Calculate line/column from css and pos if provided
  if css && pos
    @line = css.byteslice(0, pos).count("\n") + 1
    line_start = css.rindex("\n", pos - 1)
    @column = line_start ? pos - line_start : pos + 1
  else
    @line = line
    @column = column
  end

  @error_type = type

  # Build message with position info
  full_message = if @line && @column
                   "#{message} at line #{@line}, column #{@column}"
                 elsif @line
                   "#{message} at line #{@line}"
                 else
                   message
                 end

  super(full_message)
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



16
17
18
# File 'lib/cataract/error.rb', line 16

def column
  @column
end

#error_typeObject (readonly)

Returns the value of attribute error_type.



16
17
18
# File 'lib/cataract/error.rb', line 16

def error_type
  @error_type
end

#lineObject (readonly)

Returns the value of attribute line.



16
17
18
# File 'lib/cataract/error.rb', line 16

def line
  @line
end