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, or nil when there is no location to show — callers must not invent an “at ?” placeholder. Delegates to Location#to_s so the whole codebase renders locations one way.



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

def format_location
  return nil unless @location

  @location.to_s
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

‘file:line:col: message`. The location goes in front (the convention editors and humans scan for) and exactly once: if the underlying message already starts with this location it is not prepended again.



51
52
53
54
55
56
57
# File 'lib/kumi/core/errors.rb', line 51

def to_s
  prefix = format_location
  base = super
  return base if prefix.nil? || base.start_with?("#{prefix}:")

  "#{prefix}: #{base}"
end