node/error: handle the case where no position is available for inner node

This commit is contained in:
mappu 2020-04-10 16:20:38 +12:00
parent 75b13e0842
commit 8986937340
1 changed files with 6 additions and 1 deletions

View File

@ -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 {