Assisted-by: GLM 5.3 Flash
This commit is contained in:
+14
-7
@@ -642,20 +642,27 @@ sequenceDiagram
|
||||
|
||||
## Types
|
||||
|
||||
### `type SyntaxError struct{ Line int; Msg string }`
|
||||
### `type SyntaxError struct{ Line, Offset, Column int; Msg string }`
|
||||
|
||||
Describes a document the parser rejected, with the 1-based `Line` at which it
|
||||
gave up and `Error()` rendering as `interpres: line N: msg`. A malformed
|
||||
document is the usual cause; the nesting limit and an input that is not valid
|
||||
UTF-8 report through the same type. Read the structured fields with a type
|
||||
assertion or `errors.AsType`:
|
||||
Describes a document the parser rejected: the 1-based `Line` at which it gave
|
||||
up, the `Offset` in bytes the scan stopped at, the 1-based `Column` on that
|
||||
line, and `Error()` rendering as `interpres: line N: msg`. A malformed document
|
||||
is the usual cause; the nesting limit and an input that is not valid UTF-8
|
||||
report through the same type, with the UTF-8 message naming the offset of the
|
||||
first invalid byte. Read the structured fields with a type assertion or
|
||||
`errors.AsType`:
|
||||
|
||||
```go
|
||||
if se, ok := errors.AsType[*interpres.SyntaxError](err); ok {
|
||||
fmt.Println(se.Line, se.Msg)
|
||||
fmt.Println(se.Line, se.Offset, se.Column, se.Msg)
|
||||
fmt.Println(se.SourceLine(data)) // the line, with a caret under Offset
|
||||
}
|
||||
```
|
||||
|
||||
`SourceLine(src)` renders the source line the error points at from `src`,
|
||||
followed by a caret line marking the column, for messages the reader sees
|
||||
under the input.
|
||||
|
||||
### `type DecodeError struct{ Path []string; Err error }`
|
||||
|
||||
Wraps a decoding failure with the key path at which it happened. `Path` lists
|
||||
|
||||
Reference in New Issue
Block a user