Skip to content

Commit 4d5dac8

Browse files
committed
Preserve runtime error node IDs from Resolve
When absoluteAttribute.Resolve() encounters a *types.Err variable value, return it directly rather than calling Unwrap(). The Unwrap call strips the Err wrapper and its node ID, causing callers to re-label the error with the observation site's ID instead of the originating expression's ID. Additionally, avoid double-wrapping *types.Err values returned from Resolve in evalTestOnly, evalAttr, and evalExhaustiveConditional. When the error is already a *types.Err, pass it to LabelErrNode directly so that a pre-existing non-zero node ID is preserved. Fixes #1191
1 parent d19e782 commit 4d5dac8

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

interpreter/attributes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func (a *absoluteAttribute) Resolve(vars Activation) (any, error) {
349349
obj, found := v.ResolveName(nm)
350350
if found {
351351
if celErr, ok := obj.(*types.Err); ok {
352-
return nil, celErr.Unwrap()
352+
return nil, celErr
353353
}
354354
obj, isOpt, err := applyQualifiers(v, obj, a.qualifiers)
355355
if err != nil {

interpreter/interpretable.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ func (test *evalTestOnly) Eval(ctx Activation) ref.Val {
167167
val, err := test.Resolve(ctx)
168168
// Return an error if the resolve step fails
169169
if err != nil {
170+
if celErr, ok := err.(*types.Err); ok {
171+
return types.LabelErrNode(test.id, celErr)
172+
}
170173
return types.LabelErrNode(test.id, types.WrapErr(err))
171174
}
172175
if optVal, isOpt := val.(*types.Optional); isOpt {
@@ -1174,11 +1177,17 @@ func (cond *evalExhaustiveConditional) Eval(ctx Activation) ref.Val {
11741177
}
11751178
if cBool {
11761179
if tErr != nil {
1180+
if celErr, ok := tErr.(*types.Err); ok {
1181+
return types.LabelErrNode(cond.id, celErr)
1182+
}
11771183
return types.LabelErrNode(cond.id, types.WrapErr(tErr))
11781184
}
11791185
return cond.adapter.NativeToValue(tVal)
11801186
}
11811187
if fErr != nil {
1188+
if celErr, ok := fErr.(*types.Err); ok {
1189+
return types.LabelErrNode(cond.id, celErr)
1190+
}
11821191
return types.LabelErrNode(cond.id, types.WrapErr(fErr))
11831192
}
11841193
return cond.adapter.NativeToValue(fVal)
@@ -1219,6 +1228,9 @@ func (a *evalAttr) Adapter() types.Adapter {
12191228
func (a *evalAttr) Eval(ctx Activation) ref.Val {
12201229
v, err := a.attr.Resolve(ctx)
12211230
if err != nil {
1231+
if celErr, ok := err.(*types.Err); ok {
1232+
return types.LabelErrNode(a.ID(), celErr)
1233+
}
12221234
return types.LabelErrNode(a.ID(), types.WrapErr(err))
12231235
}
12241236
return a.adapter.NativeToValue(v)

0 commit comments

Comments
 (0)