Module: Kreuzberg::ErrorContext

Defined in:
lib/kreuzberg/error_context.rb

Class Method Summary collapse

Class Method Details

.classify_error(message) ⇒ Integer

Classify an error message into a Kreuzberg error code.

Analyzes an error message and returns the most likely error code (0-7). Useful for converting third-party error messages into Kreuzberg categories.

Error code mapping:

  • 0: Validation

  • 1: Parsing

  • 2: OCR

  • 3: MissingDependency

  • 4: IO

  • 5: Plugin

  • 6: UnsupportedFormat

  • 7: Internal

Examples:

Classify an error

code = Kreuzberg::ErrorContext.classify_error("File not found")
if code == 4
  puts "This is an I/O error"
end

Parameters:

  • message (String)

    The error message to classify

Returns:

  • (Integer)

    Error code (0-7)



101
102
103
104
105
# File 'lib/kreuzberg/error_context.rb', line 101

def classify_error(message)
  Kreuzberg._classify_error_native(message)
rescue StandardError
  7
end

.error_code_description(code) ⇒ String

Get the description of an error code.

Examples:

Get error code description

desc = Kreuzberg::ErrorContext.error_code_description(0)
puts desc  # => "Input validation error"

Parameters:

  • code (Integer)

    Numeric error code (0-7)

Returns:

  • (String)

    Description of the error code



129
130
131
132
133
# File 'lib/kreuzberg/error_context.rb', line 129

def error_code_description(code)
  Kreuzberg._error_code_description_native(code)
rescue StandardError
  'Unknown error code'
end

.error_code_name(code) ⇒ String

Get the human-readable name of an error code.

Examples:

Get error code name

name = Kreuzberg::ErrorContext.error_code_name(0)
puts name  # => "validation"

Parameters:

  • code (Integer)

    Numeric error code (0-7)

Returns:

  • (String)

    Human-readable error code name (e.g., “validation”, “io”)



115
116
117
118
119
# File 'lib/kreuzberg/error_context.rb', line 115

def error_code_name(code)
  Kreuzberg._error_code_name_native(code)
rescue StandardError
  'unknown'
end

.error_detailsHash

Get detailed error information from the last operation.

Returns comprehensive error details including message, code, type, source location, and panic information.

Examples:

Get error details

details = Kreuzberg::ErrorContext.error_details
puts "Error: #{details[:message]}"
puts "Code: #{details[:error_code]}"
puts "Type: #{details[:error_type]}"

Returns:

  • (Hash)

    Hash with keys: :message, :error_code, :error_type, :source_file, :source_function, :source_line, :context_info, :is_panic



72
73
74
75
76
# File 'lib/kreuzberg/error_context.rb', line 72

def error_details
  Kreuzberg._get_error_details_native
rescue StandardError
  {}
end

.last_error_codeInteger

Returns Error code constant (ERROR_CODE_* values), or 0 on success.

Examples:

Check last error

Returns:

  • (Integer)

    Error code constant (ERROR_CODE_* values), or 0 on success



10
11
12
13
14
# File 'lib/kreuzberg/error_context.rb', line 10

def last_error_code
  Kreuzberg._last_error_code_native
rescue StandardError
  0
end

.last_panic_contextErrors::PanicContext?

Get panic context information from the last error.

Returns a Kreuzberg::Errors::PanicContext object containing detailed information about the last panic that occurred in the Rust core. Includes file path, line number, function name, error message, and timestamp.

Examples:

Get panic details

panic = Kreuzberg::ErrorContext.last_panic_context
if panic
  puts "Panic at #{panic.file}:#{panic.line} in #{panic.function}"
  puts "Message: #{panic.message}"
  puts "Time: #{panic.timestamp_secs}"
end

Returns:



31
32
33
34
35
36
37
38
# File 'lib/kreuzberg/error_context.rb', line 31

def last_panic_context
  json_str = Kreuzberg._last_panic_context_json_native
  return nil unless json_str

  Errors::PanicContext.from_json(json_str)
rescue StandardError
  nil
end

.last_panic_context_jsonString?

Get panic context as raw JSON string.

Returns the panic context information as a JSON string for raw access or custom parsing. Returns nil if no panic has occurred.

Examples:

Get raw JSON panic context

json = Kreuzberg::ErrorContext.last_panic_context_json
if json
  panic_data = JSON.parse(json)
  puts panic_data
end

Returns:

  • (String, nil)

    JSON-serialized panic context, or nil if no panic



53
54
55
56
57
# File 'lib/kreuzberg/error_context.rb', line 53

def last_panic_context_json
  Kreuzberg._last_panic_context_json_native
rescue StandardError
  nil
end