contextualizeError attaches the TOML key currently being processed to errors raised while decoding a key-value expression, so that DecodeError.Key() reports the offending key (e.g. on type mismatch errors). The current key is reconstructed from d.path; when the table target is cached, d.path holds o
(err error, withTableKey bool)
| 454 | // the key-value parts, so the table key prefix is prepended. This only runs on |
| 455 | // the error path and adds no cost to successful decodes. |
| 456 | func (d *decoder) contextualizeError(err error, withTableKey bool) error { |
| 457 | var mm *typeMismatchError |
| 458 | if errors.As(err, &mm) { |
| 459 | if mm.key == nil { |
| 460 | mm.key = d.currentKey(withTableKey) |
| 461 | } |
| 462 | return err |
| 463 | } |
| 464 | var perr *unstable.ParserError |
| 465 | if errors.As(err, &perr) { |
| 466 | if perr.Key == nil { |
| 467 | perr.Key = d.currentKey(withTableKey) |
| 468 | } |
| 469 | } |
| 470 | return err |
| 471 | } |
| 472 | |
| 473 | // currentKey reconstructs the full TOML key being processed from the decoder's |
| 474 | // path. When withTableKey is true, d.path contains only the key-value parts |
no test coverage detected