diff options
Diffstat (limited to 'internal/rosa/azalea/evaluate.go')
| -rw-r--r-- | internal/rosa/azalea/evaluate.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/internal/rosa/azalea/evaluate.go b/internal/rosa/azalea/evaluate.go index 9b119100..85e20583 100644 --- a/internal/rosa/azalea/evaluate.go +++ b/internal/rosa/azalea/evaluate.go @@ -211,6 +211,18 @@ func exprTextIndent(expr any) string { return strings.ReplaceAll(ExprText(expr), "\n", "\n\t") } +// posString returns the string representation of the position of expr, if +// available. Otherwise, it returns a hardcoded string. +func posString(expr any) string { + switch v := expr.(type) { + case Func: + return v.Pos.String() + + default: + return "<unknown>" + } +} + // EvaluationError is an error and the expression it occurred in. type EvaluationError struct { Expr any @@ -225,10 +237,16 @@ func (e EvaluationError) Unwrap() error { return e.Err } func (e EvaluationError) Error() string { v, ok := errors.AsType[EvaluationError](e.Err) if ok { - return fmt.Sprintf("%v\n%s", v, ExprText(e.Expr)) + return fmt.Sprintf( + "%v\n%s\n\t%s", + v, ExprText(e.Expr), posString(e.Expr), + ) } - return fmt.Sprintf("%v\n\n%s", e.Err, ExprText(e.Expr)) + return fmt.Sprintf( + "%v\n\n%s\n\t%s", + e.Err, ExprText(e.Expr), posString(e.Expr), + ) } var ( |
