Fix nil pointer panic when schedule has no ScheduleCommon#1155
Fix nil pointer panic when schedule has no ScheduleCommon#1155
Conversation
|
@Kidswiss mind giving this a review? I think it's OK, but I need another eye. |
1f5c83c to
297b9b2
Compare
|
Applied the suggestion across all 5 schedule types — using |
|
@bastjan, golangci-lint disagrees. Should we go back or change linter settings? |
|
I tend to prefer code clarity over "nice to have" lints. |
63ff5f9 to
2de4eca
Compare
When a Schedule resource specifies a job type (e.g. backup:) with fields but omits the schedule: field, the embedded *ScheduleCommon pointer is nil. Calling GetSchedule() on it caused a nil pointer dereference crash. Add nil checks to GetSchedule() for all five schedule types: BackupSchedule, RestoreSchedule, ArchiveSchedule, CheckSchedule, and PruneSchedule. Fixes #1041 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Aarno Aukia <aarno.aukia@vshn.ch>
Use in.ScheduleCommon.Schedule instead of in.Schedule to make it clear the field comes from the embedded pointer, and why the nil check is needed. Suggested-by: @bastjan Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Aarno Aukia <aarno.aukia@vshn.ch>
2de4eca to
389f11f
Compare
Disable staticcheck QF1008 ("could remove embedded field from
selector") to allow using in.ScheduleCommon.Schedule instead of
in.Schedule. The explicit form makes it clear why the nil check
is needed — the Schedule field comes from an embedded pointer.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Aarno Aukia <aarno.aukia@vshn.ch>
|
Added a lint exclusion for QF1008 in |
Kidswiss
left a comment
There was a problem hiding this comment.
I propose to mark the SchedulerCommon.Schedule as required in addition. IMHO doesn't make much sense to specify a schedule and then NOT adding the actual schedule.
Since the parent fields are optional, this will result in a conditional require.
Summary
backup:) with fields but omits theschedule:field*ScheduleCommonpointer is nil in this case, causingGetSchedule()to panicGetSchedule()for all five schedule typesFixes #1041
Test plan
ScheduleCommonapi/v1tests still pass🤖 Generated with Claude Code