From 8986937340d43fa965fe02fd997522b031636f01 Mon Sep 17 00:00:00 2001 From: mappu Date: Fri, 10 Apr 2020 16:20:38 +1200 Subject: [PATCH] node/error: handle the case where no position is available for inner node --- node.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/node.go b/node.go index 87fc239..cf95856 100644 --- a/node.go +++ b/node.go @@ -26,7 +26,12 @@ type parseErr struct { } func (pe parseErr) Error() string { - return fmt.Sprintf("Parsing %s on line %d: %s", nodeTypeString(pe.n), pe.n.GetPosition().StartLine, pe.childErr) + positionStr := "" + if posn := pe.n.GetPosition(); posn != nil { + positionStr = fmt.Sprintf(" on line %d", posn.StartLine) + } + + return fmt.Sprintf("Parsing %s%s: %s", nodeTypeString(pe.n), positionStr, pe.childErr.Error()) } func (pe parseErr) Unwrap() error {