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 {