Skip to content

Commit

Permalink
more bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JAORMX committed Nov 7, 2023
1 parent 8870965 commit 0bbc9a1
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions internal/controlplane/handlers_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ func createProfileRulesForEntity(
Entity: entities.EntityTypeToDB(entity),
ContextualRules: marshalled,
})
if err != nil {
log.Printf("error creating profile for entity %s: %v", entity, err)
return status.Errorf(codes.Internal, "error creating profile")
}

for idx := range ruleIDs {
ruleID := ruleIDs[idx]
Expand Down Expand Up @@ -629,8 +633,7 @@ func (s *Server) UpdateProfile(ctx context.Context,
Alert: validateActionType(in.GetAlert()),
})
if err != nil {
log.Printf("error creating profile: %v", err)
return nil, status.Errorf(codes.Internal, "error creating profile")
return nil, status.Errorf(codes.Internal, "error updating profile: %v", err)
}

// Create entity rules entries
Expand Down Expand Up @@ -799,6 +802,10 @@ func updateProfileRulesForEntity(
Entity: entities.EntityTypeToDB(entity),
ContextualRules: marshalled,
})
if err != nil {
log.Printf("error updating profile for entity %s: %v", entity, err)
return err
}

for idx := range ruleIDs {
ruleID := ruleIDs[idx]
Expand All @@ -808,8 +815,12 @@ func updateProfileRulesForEntity(
RuleTypeID: ruleID,
})
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
log.Printf("the rule instantiation for rule already existed.")
continue
}
log.Printf("error creating rule instantiation: %v", err)
return status.Errorf(codes.Internal, "error creating profile")
return status.Errorf(codes.Internal, "error updating profile")
}

// Remove the rule from the old rule IDs so we
Expand Down

0 comments on commit 0bbc9a1

Please sign in to comment.