Skip to content

Commit

Permalink
Ensure error typed variables are returned as errors from Resolve (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristonianJones committed Jan 24, 2024
1 parent fb9a6ce commit 6b5d14c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions interpreter/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ func (a *absoluteAttribute) Resolve(vars Activation) (any, error) {
// determine whether the type is unknown before returning.
obj, found := vars.ResolveName(nm)
if found {
if celErr, ok := obj.(*types.Err); ok {
return nil, celErr.Unwrap()
}
obj, isOpt, err := applyQualifiers(vars, obj, a.qualifiers)
if err != nil {
return nil, err
Expand Down
20 changes: 20 additions & 0 deletions interpreter/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ func TestAttributesAbsoluteAttrType(t *testing.T) {
}
}

func TestAttributesAbsoluteAttrError(t *testing.T) {
reg := newTestRegistry(t)
attrs := NewAttributeFactory(containers.DefaultContainer, reg, reg)
vars, err := NewActivation(map[string]any{
"err": types.NewErr("invalid variable computation"),
})
if err != nil {
t.Fatalf("NewActivation() failed: %v", err)
}

// acme.a.b[4][false]
attr := attrs.AbsoluteAttribute(1, "err")
qualMsg := makeQualifier(t, attrs, nil, 2, "message")
attr.AddQualifier(qualMsg)
out, err := attr.Resolve(vars)
if err == nil {
t.Errorf("attr.Resolve('err') got %v, wanted error", out)
}
}

func TestAttributesRelativeAttr(t *testing.T) {
reg := newTestRegistry(t)
attrs := NewAttributeFactory(containers.DefaultContainer, reg, reg)
Expand Down

0 comments on commit 6b5d14c

Please sign in to comment.