Exception: RSTError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/rsyntaxtree.rb

Overview

A parse or generation failure. message is the human-readable text the CLI and the web UI display and must stay stable; the structured attributes ride alongside for machine callers (--validate, an MCP server, a repair loop). code is a Symbol; label/position locate the failure inside the offending label when one is known; hint is a one-line fix; and retryable tells a caller whether applying the hint could plausibly fix the input (false means retrying would be guessing).

Constant Summary collapse

REFERENCE =

Where the notation is written down. A hint repairs the mistake in front of it and says nothing about the rest, which is enough for a reader who knows the notation and not enough for one who was guessing at it. Given once, at the top, rather than repeated on every error.

"rsyntaxtree --notation, or https://yohasebe.github.io/rsyntaxtree/llms-full.txt"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = "Error: something unexpected occurred", code: :invalid, label: nil, position: nil, hint: nil, retryable: false) ⇒ RSTError

Returns a new instance of RSTError.



124
125
126
127
128
129
130
131
132
133
134
# File 'lib/rsyntaxtree.rb', line 124

def initialize(msg = "Error: something unexpected occurred", code: :invalid, label: nil, position: nil, hint: nil, retryable: false)
  # Non-destructive: every file here carries frozen_string_literal, so
  # mutating the message in place turned a raise with a plain literal into
  # a FrozenError from inside the error class itself.
  @code = code
  @label = label
  @position = position
  @hint = hint
  @retryable = retryable
  super(msg.gsub(WHITESPACE_BLOCK, "<>"))
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



122
123
124
# File 'lib/rsyntaxtree.rb', line 122

def code
  @code
end

#hintObject (readonly)

Returns the value of attribute hint.



122
123
124
# File 'lib/rsyntaxtree.rb', line 122

def hint
  @hint
end

#labelObject (readonly)

Returns the value of attribute label.



122
123
124
# File 'lib/rsyntaxtree.rb', line 122

def label
  @label
end

#positionObject (readonly)

Returns the value of attribute position.



122
123
124
# File 'lib/rsyntaxtree.rb', line 122

def position
  @position
end

#retryableObject (readonly)

Returns the value of attribute retryable.



122
123
124
# File 'lib/rsyntaxtree.rb', line 122

def retryable
  @retryable
end

Instance Method Details

#to_hObject



142
143
144
145
146
147
148
149
150
151
# File 'lib/rsyntaxtree.rb', line 142

def to_h
  { "ok" => false,
    "errors" => [{ "code" => code.to_s,
                   "message" => message,
                   "label" => label,
                   "position" => position,
                   "hint" => hint,
                   "retryable" => retryable }.compact],
    "reference" => REFERENCE }
end