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

Methods inherited from MirahError

#inspect

Constructor Details

#initialize(message, node = nil) ⇒ NodeError

Returns a new instance of NodeError.



34
35
36
37
38
# File 'lib/mirah/errors.rb', line 34

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.



32
33
34
# File 'lib/mirah/errors.rb', line 32

def node
  @node
end

Class Method Details

.wrap(ex, node) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mirah/errors.rb', line 45

def self.wrap(ex, node)
  case ex
  when NodeError
    ex.node ||= node
    ex
  when MirahError
    ex.position ||= node.position
    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)
    new_ex
  end
end

Instance Method Details

#positionObject



62
63
64
65
66
67
68
# File 'lib/mirah/errors.rb', line 62

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