Exception: Kumi::Core::Errors::LocatedError

Inherits:
Error
  • Object
show all
Defined in:
lib/kumi/core/errors.rb

Direct Known Subclasses

SemanticError, SyntaxError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, location = nil) ⇒ LocatedError

Returns a new instance of LocatedError.



11
12
13
14
# File 'lib/kumi/core/errors.rb', line 11

def initialize(message, location = nil)
  super(message)
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



9
10
11
# File 'lib/kumi/core/errors.rb', line 9

def location
  @location
end

Instance Method Details

#format_locationObject

Format location for error messages



40
41
42
43
44
45
46
# File 'lib/kumi/core/errors.rb', line 40

def format_location
  if @location
    "at #{@location.file} line=#{@location.line} column=#{@location.column}"
  else
    "at ?"
  end
end

#has_location?Boolean

Check if location information is present and valid

Returns:

  • (Boolean)


35
36
37
# File 'lib/kumi/core/errors.rb', line 35

def has_location?
  @location && @location.file && @location.line && @location.line > 0
end

#location_columnObject Also known as: column



25
26
27
# File 'lib/kumi/core/errors.rb', line 25

def location_column
  @location&.column
end

#location_fileObject Also known as: path

Extract location components cleanly



17
18
19
# File 'lib/kumi/core/errors.rb', line 17

def location_file
  @location&.file
end

#location_lineObject Also known as: line



21
22
23
# File 'lib/kumi/core/errors.rb', line 21

def location_line
  @location&.line
end

#to_sObject



48
49
50
51
52
53
54
# File 'lib/kumi/core/errors.rb', line 48

def to_s
  if @location
    "#{super} #{format_location}"
  else
    super
  end
end