From 5a77db656ead2d1fb36b665d099bc45a4558dd58 Mon Sep 17 00:00:00 2001 From: Vaibhav Kamra Date: Fri, 1 Dec 2023 11:33:19 -0800 Subject: [PATCH] Fix panic in GroupByID call (#4778) `resp` is nil if there's an error and `getGroupFromResponse` will panic. --- #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [ ] :sunflower: Feature - [x] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Issue(s) * # #### Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- src/pkg/services/m365/api/groups.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pkg/services/m365/api/groups.go b/src/pkg/services/m365/api/groups.go index 8a1622e66..60431d101 100644 --- a/src/pkg/services/m365/api/groups.go +++ b/src/pkg/services/m365/api/groups.go @@ -150,15 +150,15 @@ func (c Groups) GetByID( } resp, err := service.Client().Groups().Get(ctx, opts) - if err != nil { - if graph.IsErrResourceLocked(err) { - err = clues.Stack(graph.ErrResourceLocked, err) - } - - logger.CtxErr(ctx, err).Info("finding group by email, falling back to display name") + if err == nil { + return getGroupFromResponse(ctx, resp) } - return getGroupFromResponse(ctx, resp) + if graph.IsErrResourceLocked(err) { + err = clues.Stack(graph.ErrResourceLocked, err) + } + + logger.CtxErr(ctx, err).Info("finding group by email, falling back to display name") } // fall back to display name