module RubyLLM::AgUI::ErrorSanitizer

Turns an exception into a safe (message, code) pair for RUN_ERROR.

Upstream Rails examples put ‘e.message` straight into RUN_ERROR, which can leak prompts, request bodies, API keys and internal paths. This module never does that: it classifies the error by class and returns a fixed, public message. The raw exception goes to the host logger, if the host configured one, and nowhere else.

Constants

FALLBACK
MESSAGES

Ordered by specificity. The first ancestor of the error whose name is a key wins, so subclass relationships are respected without loading optional error classes eagerly.

Public Instance Methods

classify(error) click to toggle source

Returns the [message, code] pair for error, falling back to FALLBACK.

# File lib/ruby_llm/ag_ui/error_sanitizer.rb, line 59
def classify(error)
  names = error.class.ancestors.map(&:name).compact
  names.each do |name|
    entry = MESSAGES[name]
    return entry if entry
  end
  nil
end
sanitize(error) click to toggle source

Returns a [message, code] pair safe to put on the wire.

# File lib/ruby_llm/ag_ui/error_sanitizer.rb, line 53
def sanitize(error)
  match = classify(error)
  match || FALLBACK
end