fix: Prevent nil pointer panic in monitor loop#24
fix: Prevent nil pointer panic in monitor loop#24Attacktive wants to merge 4 commits intofly-apps:mainfrom
Conversation
| } else { | ||
| log.WithError(err).Errorf("failed to get machine %s: %v", job.MachineID.String, err) | ||
| } | ||
| log.WithError(err).Errorf("failed to get machine %s: %v", job.MachineID.String, err) |
There was a problem hiding this comment.
I'm not 100% sure if it deliberately proceeds in non-404 cases, so let me know if it does. 🙂
There was a problem hiding this comment.
Pull request overview
This PR fixes a potential nil pointer dereference panic in the evaluateJob function by ensuring proper error handling when MachineGet fails and by adding a defensive nil check even when no error is returned.
Changes:
- Added early return when
MachineGetreturns a non-404 error to prevent further processing - Added explicit nil check for the machine object before accessing its properties
- Restructured error handling logic to use if-else for better control flow
Comments suppressed due to low confidence (1)
internal/cron/monitor.go:79
- The error is being logged with both
WithError(err)and%vformatting of the same error, which results in duplicate error information in the log output. Remove the: %vanderrparameter from the format string to avoid redundancy.
log.WithError(err).Errorf("failed to get machine %s: %v", job.MachineID.String, err)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
internal/cron/monitor.go
Outdated
| } | ||
| return nil | ||
| } else { | ||
| log.WithError(err).Errorf("failed to get machine %s: %v", job.MachineID.String, err) |
There was a problem hiding this comment.
The error is being logged with both WithError(err) and %v formatting of the same error, which results in duplicate error information in the log output. Remove the : %v and err parameter from the format string to avoid redundancy.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
The
evaluateJobfunction was proceeding to process job events even whenMachineGetwas kind of unsuccessful; the exit code404alone is covered.changes:
returnwhenMachineGetreturns an error (non-404).nileven if no error is returned