Assisted-by: GLM 5.3 Flash
This commit is contained in:
+15
-9
@@ -738,26 +738,32 @@ if se, ok := errors.AsType[*interpres.SyntaxError](err); ok {
|
||||
followed by a caret line marking the column, for messages the reader sees
|
||||
under the input.
|
||||
|
||||
### `type DecodeError struct{ Path []string; Err error }`
|
||||
### `type DecodeError struct{ Path Path; Err error }`
|
||||
|
||||
Wraps a decoding failure with the key path at which it happened. `Path` lists
|
||||
one segment per level from the document root, the outermost key first: a key
|
||||
contributes its name, an array element its bracketed index, so the path of the
|
||||
`weight` field in the first item reads `["items", "[0]", "weight"]`. The
|
||||
rendered message is unchanged by the type; read the fields instead of parsing
|
||||
the message:
|
||||
`weight` field in the first item reads `["items", "[0]", "weight"]` and its
|
||||
`String()` renders `items[0].weight`. Read the fields instead of parsing the
|
||||
message:
|
||||
|
||||
```go
|
||||
if de, ok := errors.AsType[*interpres.DecodeError](err); ok {
|
||||
fmt.Println(de.Path, de.Err)
|
||||
fmt.Println(de.Path.String(), de.Err)
|
||||
}
|
||||
```
|
||||
|
||||
### `type EncodeError struct{ Path string; Err error }`
|
||||
### `type EncodeError struct{ Path Path; Err error }`
|
||||
|
||||
Wraps an encoding failure with the key path of the value that failed, in the
|
||||
document's own notation: `server.ports[2]`. Read it with `errors.AsType` the
|
||||
same way.
|
||||
Wraps an encoding failure with the key path of the value that failed, the
|
||||
same `Path` type the decode error carries, so `server.ports[2]` reads the
|
||||
same on both sides. Read it with `errors.AsType` the same way.
|
||||
|
||||
### `type Path []string`
|
||||
|
||||
The path both error wrappers carry, one segment per level from the document
|
||||
root. `String()` renders the TOML notation: keys join with dots, an index
|
||||
attaches to the previous segment in brackets, `items[0].weight`.
|
||||
|
||||
### `type Decoder`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user