Exception: Mirah::NodeError

Inherits:
MirahError
  • Object
show all
Defined in:
lib/mirah/errors.rb

Instance Attribute Summary collapse

Attributes inherited from MirahError

#cause

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, node = nil) ⇒ NodeError

Returns a new instance of NodeError.



15
16
17
18
19
# File 'lib/mirah/errors.rb', line 15

def initialize(message, node=nil)
  position = node.position if node
  super(message, position)
  @node = node
end

Instance Attribute Details

#nodeObject

Returns the value of attribute node.



13
14
15
# File 'lib/mirah/errors.rb', line 13

def node
  @node
end

Class Method Details

.wrap(ex, node) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mirah/errors.rb', line 26

def self.wrap(ex, node)
  if ex.kind_of?(NodeError)
    ex.node ||= node
    return ex
  elsif ex.kind_of?(MirahError)
    ex.position ||= node.position
    return ex
  else
    new_ex = new(ex.message, node)
    new_ex.cause = ex
    new_ex.position ||= ex.position if ex.respond_to?(:position)
    new_ex.set_backtrace(ex.backtrace)
    return new_ex
  end
end

Instance Method Details

#positionObject



42
43
44
45
46
47
48
# File 'lib/mirah/errors.rb', line 42

def position
  if node && node.position
    node.position
  else
    super
  end
end