Skip to content

Commit

Permalink
[core] Fix counters and string building issue in TasksDeploymentError
Browse files Browse the repository at this point in the history
  • Loading branch information
teo committed Sep 4, 2023
1 parent 7983231 commit a3381ba
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion core/task/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,47 @@ type TasksDeploymentError struct {
}

func (r TasksDeploymentError) Error() string {
return fmt.Sprintf("deployment failed for %d critical tasks, and %d non-critical tasks; critical tasks: [%s]; non-critical tasks: [%s]", len(r.failedCriticalDescriptors), len(r.failedNonCriticalDescriptors), r.failedCriticalDescriptors.String(), r.failedNonCriticalDescriptors.String())
failedCritCount := len(r.failedCriticalDescriptors)
failedNonCritCount := len(r.failedNonCriticalDescriptors)
undepCritCount := len(r.undeployableCriticalDescriptors)
undepNonCritCount := len(r.undeployableNonCriticalDescriptors)

failedCritStr := fmt.Sprintf("%d failed [%s]", failedCritCount, r.failedCriticalDescriptors.String())
undepCritStr := fmt.Sprintf("%d undeployable [%s]", undepCritCount, r.undeployableCriticalDescriptors.String())

failedNonCritStr := fmt.Sprintf("%d failed [%s]", failedNonCritCount, r.failedNonCriticalDescriptors.String())
undepNonCritStr := fmt.Sprintf("%d undeployable [%s]", undepNonCritCount, r.undeployableNonCriticalDescriptors.String())

if failedCritCount == 0 {
failedCritStr = "0 failed"
}
if undepCritCount == 0 {
undepCritStr = "0 undeployable"
}

if failedNonCritCount == 0 {
failedNonCritStr = "0 failed"
}
if undepNonCritCount == 0 {
undepNonCritStr = "0 undeployable"
}

critStr := fmt.Sprintf("%s, %s", failedCritStr, undepCritStr)
nonCritStr := fmt.Sprintf("%s, %s", failedNonCritStr, undepNonCritStr)

totalCritCount := failedCritCount + undepCritCount
totalNonCritCount := failedNonCritCount + undepNonCritCount

total := totalCritCount + totalNonCritCount

return fmt.Sprintf(
"deployment failed for %d tasks: %d critical (%s), %d non-critical (%s)",
total,
totalCritCount,
critStr,
totalNonCritCount,
nonCritStr,
)
}

type TaskAlreadyReleasedError taskErrorBase
Expand Down

0 comments on commit a3381ba

Please sign in to comment.