Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/types/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ func ValOrErr(val ref.Val, format string, args ...any) ref.Val {

// WrapErr wraps an existing Go error value into a CEL Err value.
func WrapErr(err error) ref.Val {
if err, ok := err.(*Err); ok {
return err
}
return &Err{error: err}
}

Expand Down
2 changes: 1 addition & 1 deletion interpreter/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (a *absoluteAttribute) Resolve(vars Activation) (any, error) {
obj, found := v.ResolveName(nm)
if found {
if celErr, ok := obj.(*types.Err); ok {
return nil, celErr.Unwrap()
return nil, celErr
Comment thread
TristonianJones marked this conversation as resolved.
}
obj, isOpt, err := applyQualifiers(v, obj, a.qualifiers)
if err != nil {
Expand Down
25 changes: 25 additions & 0 deletions interpreter/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,21 @@ func TestAttributeStateTracking(t *testing.T) {
),
out: types.NewUnknown(5, types.QualifyAttribute[string](types.NewAttributeTrail("a"), "b")),
},
{
expr: `['a', b.val, 'c'].filter(i, i + 'b' != 'ab')`,
vars: []*decls.VariableDecl{
decls.NewVariable("b", types.NewMapType(types.StringType, types.DynType)),
},
in: partialActivation(
map[string]any{
"b": map[string]any{
"val": 1,
},
},
),
// Error node 9 corresponds to the `i + 'b'` expression
out: types.LabelErrNode(9, types.NoSuchOverloadErr()),
},
}
for _, test := range tests {
tc := test
Expand Down Expand Up @@ -1170,9 +1185,19 @@ func TestAttributeStateTracking(t *testing.T) {
if !reflect.DeepEqual(tc.out, out) {
t.Errorf("got %v, wanted %v", out, tc.out)
}
} else if types.IsError(tc.out) && types.IsError(out) {
if tc.out.(*types.Err).Error() != out.(*types.Err).Error() {
t.Errorf("got %v, wanted %v", out, tc.out)
}
} else if tc.out.Equal(out) != types.True {
t.Errorf("got %v, wanted %v", out, tc.out)
}
if err, isErr := out.(*types.Err); isErr && err.NodeID() != 0 {
wantErr := tc.out.(*types.Err)
if err.NodeID() != wantErr.NodeID() {
t.Errorf("err.NodeID() got %d, wanted %d", err.NodeID(), wantErr.NodeID())
}
}
for id, val := range tc.state {
stVal, found := holder.st.Value(id)
if !found {
Expand Down