Exception: RSTError
- Inherits:
-
StandardError
- Object
- StandardError
- RSTError
- 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
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#hint ⇒ Object
readonly
Returns the value of attribute hint.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#retryable ⇒ Object
readonly
Returns the value of attribute retryable.
Instance Method Summary collapse
-
#initialize(msg = "Error: something unexpected occurred", code: :invalid, label: nil, position: nil, hint: nil, retryable: false) ⇒ RSTError
constructor
A new instance of RSTError.
- #to_h ⇒ Object
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.
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/rsyntaxtree.rb', line 104 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
#code ⇒ Object (readonly)
Returns the value of attribute code.
102 103 104 |
# File 'lib/rsyntaxtree.rb', line 102 def code @code end |
#hint ⇒ Object (readonly)
Returns the value of attribute hint.
102 103 104 |
# File 'lib/rsyntaxtree.rb', line 102 def hint @hint end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
102 103 104 |
# File 'lib/rsyntaxtree.rb', line 102 def label @label end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
102 103 104 |
# File 'lib/rsyntaxtree.rb', line 102 def position @position end |
#retryable ⇒ Object (readonly)
Returns the value of attribute retryable.
102 103 104 |
# File 'lib/rsyntaxtree.rb', line 102 def retryable @retryable end |
Instance Method Details
#to_h ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/rsyntaxtree.rb', line 122 def to_h { "ok" => false, "errors" => [{ "code" => code.to_s, "message" => , "label" => label, "position" => position, "hint" => hint, "retryable" => retryable }.compact], "reference" => REFERENCE } end |