@@ -80,7 +80,7 @@ func run(cmd *cobra.Command, _ []string) error {
80
80
81
81
defer func () {
82
82
if err != nil {
83
- handleCADFailure (err , investigationResources )
83
+ handleCADFailure (err , investigationResources , pdClient )
84
84
}
85
85
}()
86
86
@@ -155,17 +155,26 @@ func run(cmd *cobra.Command, _ []string) error {
155
155
return err
156
156
}
157
157
158
- func handleCADFailure (err error , resources * investigation.Resources ) {
158
+ func handleCADFailure (err error , resources * investigation.Resources , pdClient * pagerduty. SdkClient ) {
159
159
logging .Errorf ("CAD investigation failed: %v" , err )
160
160
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
+ }
162
168
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
+ }
167
176
} 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. " )
169
178
}
170
179
}
171
180
0 commit comments