MCPcopy
hub / github.com/pelletier/go-toml / wrapSeenError

Method wrapSeenError

unmarshaler.go:626–656  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

624// inline table, node is the enclosing key-value expression, so the error
625// points at that expression's key.
626func (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
658func (d *decoder) handleRootExpression(expr *unstable.Node, root reflect.Value) error {
659 first, err := d.seen.CheckExpression(expr)

Callers 1

handleRootExpressionMethod · 0.95

Calls 5

NodeMethod · 0.80
RawMethod · 0.80
KeyMethod · 0.45
NextMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected