Skip to content

Commit

Permalink
chore: explicitly check for NotFound
Browse files Browse the repository at this point in the history
We shouldn't rely on the fact that a callee only returns NotFound to pun
err != nil. Instead, explicitly handle NotFound and throw out for other
error types.
  • Loading branch information
manadart committed Sep 19, 2024
1 parent 9cab7d9 commit 415278a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions worker/uniter/relation/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func (r *relationsResolver) NextOp(
return nil, resolver.ErrNoOperation
}

// processRelationSnapshot reconciles the local and remote states for a
// single relation and determines what hoof (if any) should be fired.
func (r *relationsResolver) processRelationSnapshot(
relationID int,
relationSnapshot remotestate.RelationSnapshot,
Expand All @@ -139,6 +141,9 @@ func (r *relationsResolver) processRelationSnapshot(
// to be fired for this relation.
relState, err := r.stateTracker.State(relationID)
if err != nil {
if !errors.Is(err, errors.NotFound) {
return nil, errors.Trace(err)
}
relState = NewState(relationID)
}
hInfo, err := r.nextHookForRelation(relState, relationSnapshot, remoteBroken)
Expand Down
2 changes: 1 addition & 1 deletion worker/uniter/relation/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ func (s *mockRelationResolverSuite) expectIsImplicitFalse(id int) {

func (s *mockRelationResolverSuite) expectStateUnknown(id int) {
exp := s.mockRelStTracker.EXPECT()
exp.State(id).Return(nil, errors.Errorf("unknown relation: %d", id))
exp.State(id).Return(nil, errors.NotFoundf("relation: %d", id))
}

func (s *mockRelationResolverSuite) expectState(st relation.State) {
Expand Down

0 comments on commit 415278a

Please sign in to comment.