wrapSeenError turns an error returned by SeenTracker.CheckExpression into a ParserError carrying the position and key of the offending expression, so that redefinition and duplicate-key errors are reported as a DecodeError with context (see issue #668). The highlight spans the expression's key. Unl
(node *unstable.Node, err error)
| 624 | // inline table, node is the enclosing key-value expression, so the error |
| 625 | // points at that expression's key. |
| 626 | func (d *decoder) wrapSeenError(node *unstable.Node, err error) error { |
| 627 | if err == nil { |
| 628 | return nil |
| 629 | } |
| 630 | |
| 631 | var key Key |
| 632 | var start, end unstable.Range |
| 633 | it := node.Key() |
| 634 | for it.Next() { |
| 635 | n := it.Node() |
| 636 | key = append(key, string(n.Data)) |
| 637 | if len(key) == 1 { |
| 638 | start = n.Raw |
| 639 | } |
| 640 | end = n.Raw |
| 641 | } |
| 642 | |
| 643 | var highlight []byte |
| 644 | if len(key) > 0 { |
| 645 | highlight = d.p.Raw(unstable.Range{ |
| 646 | Offset: start.Offset, |
| 647 | Length: end.Offset + end.Length - start.Offset, |
| 648 | }) |
| 649 | } |
| 650 | |
| 651 | return &unstable.ParserError{ |
| 652 | Highlight: highlight, |
| 653 | Message: strings.TrimPrefix(err.Error(), "toml: "), |
| 654 | Key: key, |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | func (d *decoder) handleRootExpression(expr *unstable.Node, root reflect.Value) error { |
| 659 | first, err := d.seen.CheckExpression(expr) |