Skip to content

Commit 160df6d

Browse files
Merge pull request #399 from MateSaary/OSD-28224-fix
OSD-28224: Add nil safety to handleCADFailure
2 parents 75caf48 + b385bbb commit 160df6d

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

cadctl/cmd/investigate/investigate.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func run(cmd *cobra.Command, _ []string) error {
8080

8181
defer func() {
8282
if err != nil {
83-
handleCADFailure(err, investigationResources)
83+
handleCADFailure(err, investigationResources, pdClient)
8484
}
8585
}()
8686

@@ -155,17 +155,26 @@ func run(cmd *cobra.Command, _ []string) error {
155155
return err
156156
}
157157

158-
func handleCADFailure(err error, resources *investigation.Resources) {
158+
func handleCADFailure(err error, resources *investigation.Resources, pdClient *pagerduty.SdkClient) {
159159
logging.Errorf("CAD investigation failed: %v", err)
160160

161-
notes := resources.Notes
161+
var notes string
162+
if resources != nil && resources.Notes != nil {
163+
resources.Notes.AppendWarning("🚨 CAD investigation failed, CAD team has been notified. Please investigate manually. 🚨")
164+
notes = resources.Notes.String()
165+
} else {
166+
notes = "🚨 CAD investigation failed prior to resource initilization, CAD team has been notified. Please investigate manually. 🚨"
167+
}
162168

163-
notes.AppendWarning("🚨 CAD investigation failed, CAD team has been notified. Please investigate manually. 🚨")
164-
pdErr := resources.PdClient.EscalateIncidentWithNote(notes.String())
165-
if pdErr != nil {
166-
logging.Errorf("Failed to escalate notes to PagerDuty: %v", pdErr)
169+
if pdClient != nil {
170+
pdErr := pdClient.EscalateIncidentWithNote(notes)
171+
if pdErr != nil {
172+
logging.Errorf("Failed to escalate notes to PagerDuty: %v", pdErr)
173+
} else {
174+
logging.Info("CAD failure & incident notes added to PagerDuty")
175+
}
167176
} else {
168-
logging.Info("CAD failure & incident notes added to PagerDuty")
177+
logging.Errorf("Failed to obtain PagerDuty client, unable to escalate CAD failure to PagerDuty notes.")
169178
}
170179
}
171180

0 commit comments

Comments
 (0)