diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-10-30 23:37:34 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-10-30 23:38:34 +0900 |
| commit | 3c0505619920d8656b332ef0a23295b0d13f2253 (patch) | |
| tree | 206cfca2f4aa4596bbc34eeab2fed7be6e7b2354 /internal/rosa/azalea/evaluate.go | |
| parent | be0ef63ad467a7efbbecb92d40d1f73af82a0d84 (diff) | |
internal/rosa/azalea: record position in func expr
This is included in the evaluation error message.
Signed-off-by: Ophestra <cat@gensokyo.uk>
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 ( |
