Exception: Kumi::Core::Errors::LocatedError
- Defined in:
- lib/kumi/core/errors.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Instance Method Summary collapse
-
#format_location ⇒ Object
Format location for error messages, or nil when there is no location to show — callers must not invent an “at ?” placeholder.
-
#has_location? ⇒ Boolean
Check if location information is present and valid.
-
#initialize(message, location = nil) ⇒ LocatedError
constructor
A new instance of LocatedError.
- #location_column ⇒ Object (also: #column)
-
#location_file ⇒ Object
(also: #path)
Extract location components cleanly.
- #location_line ⇒ Object (also: #line)
-
#to_s ⇒ Object
‘file:line:col: message`.
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(, location = nil) super() @location = location end |
Instance Attribute Details
#location ⇒ Object (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_location ⇒ Object
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
35 36 37 |
# File 'lib/kumi/core/errors.rb', line 35 def has_location? @location && @location.file && @location.line && @location.line > 0 end |
#location_column ⇒ Object Also known as: column
25 26 27 |
# File 'lib/kumi/core/errors.rb', line 25 def location_column @location&.column end |
#location_file ⇒ Object 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_line ⇒ Object Also known as: line
21 22 23 |
# File 'lib/kumi/core/errors.rb', line 21 def location_line @location&.line end |
#to_s ⇒ Object
‘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 |