Class: Kumi::Core::ErrorReporter::ErrorEntry

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

Overview

Standard error structure for internal use Provides clean access to location components (file, line, column)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location:, message:, type: :semantic, context: {}, backtrace: nil) ⇒ ErrorEntry

Returns a new instance of ErrorEntry.



19
20
21
22
23
24
25
# File 'lib/kumi/core/error_reporter.rb', line 19

def initialize(location:, message:, type: :semantic, context: {}, backtrace: nil)
  @location = location
  @message = message
  @type = type
  @context = context
  @backtrace = backtrace
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



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

def backtrace
  @backtrace
end

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#messageObject (readonly)

Returns the value of attribute message.



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

def message
  @message
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#columnObject



46
47
48
# File 'lib/kumi/core/error_reporter.rb', line 46

def column
  location.is_a?(Syntax::Location) ? location.column : nil
end

#fileObject

Extract location components cleanly



38
39
40
# File 'lib/kumi/core/error_reporter.rb', line 38

def file
  location.is_a?(Syntax::Location) ? location.file : nil
end

#lineObject



42
43
44
# File 'lib/kumi/core/error_reporter.rb', line 42

def line
  location.is_a?(Syntax::Location) ? location.line : nil
end

#location?Boolean

Check if location information is present

Returns:

  • (Boolean)


33
34
35
# File 'lib/kumi/core/error_reporter.rb', line 33

def location?
  location && !location.is_a?(Symbol)
end

#pathObject

Alias for consistency



51
52
53
# File 'lib/kumi/core/error_reporter.rb', line 51

def path
  file
end

#to_sObject



27
28
29
30
# File 'lib/kumi/core/error_reporter.rb', line 27

def to_s
  location_str = format_location(location)
  "#{location_str}: #{message}"
end

#valid_location?Boolean

Check if location is valid (has file and line)

Returns:

  • (Boolean)


56
57
58
# File 'lib/kumi/core/error_reporter.rb', line 56

def valid_location?
  !!(location? && file && line && line > 0)
end