Skip to content

Commit

Permalink
Check that all the checks exist upfront, rather than erroring out par…
Browse files Browse the repository at this point in the history
…tway through.
  • Loading branch information
tonyandrewmeyer committed Jan 17, 2025
1 parent 59365b5 commit cf7174d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions internals/overlord/checkstate/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,15 @@ func (m *CheckManager) StartChecks(currentPlan *plan.Plan, checks []string) ([]s
m.state.Lock()
defer m.state.Unlock()

var started []string
// If any check specified is not in the plan, return an error.
for _, name := range checks {
// If the check is not in the plan, return an error.
check, ok := currentPlan.Checks[name]
if !ok {
if _, ok := currentPlan.Checks[name]; !ok {
return nil, fmt.Errorf("cannot find check %q in plan", name)
}
}
var started []string
for _, name := range checks {
check := currentPlan.Checks[name] // We know this is ok because we checked it above.

Check failure on line 397 in internals/overlord/checkstate/manager.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gci)

Check failure on line 397 in internals/overlord/checkstate/manager.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gci)
info, ok := m.checks[name]
if !ok {
panic(fmt.Sprintf("check %s is in the plan but not known to the manager", name))
Expand All @@ -416,13 +418,15 @@ func (m *CheckManager) StopChecks(currentPlan *plan.Plan, checks []string) ([]st
m.state.Lock()
defer m.state.Unlock()

var stopped []string
// If any check specified is not in the plan, return an error.
for _, name := range checks {
// If the check is not in the current plan, return an error.
check, ok := currentPlan.Checks[name]
if !ok {
if _, ok := currentPlan.Checks[name]; !ok {
return nil, fmt.Errorf("cannot find check %q in plan", name)
}
}
var stopped []string
for _, name := range checks {
check := currentPlan.Checks[name] // We know this is ok because we checked it above.

Check failure on line 429 in internals/overlord/checkstate/manager.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gci)

Check failure on line 429 in internals/overlord/checkstate/manager.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gci)
info, ok := m.checks[name]
if !ok {
panic(fmt.Sprintf("check %s is in the plan but not known to the manager", name))
Expand Down

0 comments on commit cf7174d

Please sign in to comment.