Skip to content

Commit

Permalink
improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 committed Sep 2, 2024
1 parent c0fd677 commit aa5e163
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cmd/jimmctl/cmd/relation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,11 @@ func (s *relationSuite) TestListRelations(c *gc.C) {
}, {
Object: "group-group-1#member",
Relation: "administrator",
TargetObject: "model-" + env.controllers[0].Name + ":" + env.models[0].OwnerIdentityName + "/" + env.models[0].Name,
TargetObject: "model-" + env.models[0].OwnerIdentityName + "/" + env.models[0].Name,
}, {
Object: "user-" + env.users[1].Name,
Relation: "administrator",
TargetObject: "applicationoffer-" + env.controllers[0].Name + ":" + env.applicationOffers[0].Model.OwnerIdentityName + "/" + env.applicationOffers[0].Model.Name + "." + env.applicationOffers[0].Name,
TargetObject: "applicationoffer-" + env.applicationOffers[0].URL,
}, {
Object: "user-" + env.users[0].Name,
Relation: "administrator",
Expand Down
2 changes: 1 addition & 1 deletion internal/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const (
CodeStillAlive Code = apiparams.CodeStillAlive
CodeUnauthorized Code = jujuparams.CodeUnauthorized
CodeUpgradeInProgress Code = jujuparams.CodeUpgradeInProgress
CodeFailedToParseTupleKey Code = "failed to parse tuple object key"
CodeFailedToParseTupleKey Code = "failed to parse tuple"
CodeFailedToResolveTupleResource Code = "failed resolve resource"
CodeOpenFGARequestFailed Code = "failed request to OpenFGA"
CodeJWKSRetrievalFailed Code = "jwks retrieval failure"
Expand Down
4 changes: 4 additions & 0 deletions internal/jimm/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ func TestResolveTupleObjectHandlesErrors(t *testing.T) {
input: "abc",
want: "failed to setup tag resolver: tag is not properly formatted",
},
{
input: "model-test-unknowncontroller-1:[email protected]/test-model-1",
want: "model not found",
},
}
for i, tc := range tests {
t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions internal/jujuapi/access_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package jujuapi

import (
"context"
"fmt"
"strconv"
"time"

Expand Down Expand Up @@ -198,7 +199,7 @@ func (r *controllerRoot) parseTuple(ctx context.Context, tuple apiparams.Relatio
// to be specific to the erroneous offender.
parseTagError := func(msg string, key string, err error) error {
zapctx.Debug(ctx, msg, zap.String("key", key), zap.Error(err))
return errors.E(op, errors.CodeFailedToParseTupleKey, err, msg+" "+key)
return errors.E(op, errors.CodeFailedToParseTupleKey, fmt.Errorf("%s, key %s: %w", msg, key, err))
}

if tuple.TargetObject == "" {
Expand All @@ -207,14 +208,14 @@ func (r *controllerRoot) parseTuple(ctx context.Context, tuple apiparams.Relatio
if tuple.TargetObject != "" {
targetTag, err := r.jimm.ParseTag(ctx, tuple.TargetObject)
if err != nil {
return nil, parseTagError("failed to parse tuple target object key", tuple.TargetObject, err)
return nil, parseTagError("failed to parse tuple target", tuple.TargetObject, err)
}
t.Target = targetTag
}
if tuple.Object != "" {
objectTag, err := r.jimm.ParseTag(ctx, tuple.Object)
if err != nil {
return nil, parseTagError("failed to parse tuple object key", tuple.Object, err)
return nil, parseTagError("failed to parse tuple object", tuple.Object, err)
}
t.Object = objectTag
}
Expand Down
9 changes: 9 additions & 0 deletions internal/jujuapi/access_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,15 @@ func (s *accessControlSuite) TestListRelationshipTuples(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
c.Assert(response.Tuples, jc.DeepEquals, []apiparams.RelationshipTuple{tuples[3]})
c.Assert(len(response.Errors), gc.Equals, 0)

// Test error message when a resource is not found
_, err = client.ListRelationshipTuples(&apiparams.ListRelationshipTuplesRequest{
Tuple: apiparams.RelationshipTuple{
TargetObject: "applicationoffer-" + "fake-offer",
},
ResolveUUIDs: true,
})
c.Assert(err, gc.ErrorMatches, "failed to parse tuple target, key applicationoffer-fake-offer: application offer not found.*")
}

func (s *accessControlSuite) TestListRelationshipTuplesNoUUIDResolution(c *gc.C) {
Expand Down

0 comments on commit aa5e163

Please sign in to comment.