Skip to content

Commit fd50797

Browse files
committed
fix(nelm): refactor error handling in converge
Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
1 parent 8b353af commit fd50797

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

cmd/werf/converge/converge.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -774,30 +774,30 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
774774
NetworkParallelism: networkParallelism,
775775
})
776776

777-
var finalErrs []error
777+
var criticalErrs, nonCriticalErrs []error
778778

779779
planExecutionErr := planExecutor.Execute(ctx)
780780
if planExecutionErr != nil {
781-
finalErrs = append(finalErrs, fmt.Errorf("error executing deploy plan: %w", planExecutionErr))
781+
criticalErrs = append(criticalErrs, fmt.Errorf("error executing deploy plan: %w", planExecutionErr))
782782
}
783783

784784
var worthyCompletedOps []opertn.Operation
785785
if ops, found, err := plan.WorthyCompletedOperations(); err != nil {
786-
finalErrs = append(finalErrs, fmt.Errorf("error getting worthy completed operations: %w", err))
786+
nonCriticalErrs = append(nonCriticalErrs, fmt.Errorf("error getting worthy completed operations: %w", err))
787787
} else if found {
788788
worthyCompletedOps = ops
789789
}
790790

791791
var worthyCanceledOps []opertn.Operation
792792
if ops, found, err := plan.WorthyCanceledOperations(); err != nil {
793-
finalErrs = append(finalErrs, fmt.Errorf("error getting worthy canceled operations: %w", err))
793+
nonCriticalErrs = append(nonCriticalErrs, fmt.Errorf("error getting worthy canceled operations: %w", err))
794794
} else if found {
795795
worthyCanceledOps = ops
796796
}
797797

798798
var worthyFailedOps []opertn.Operation
799799
if ops, found, err := plan.WorthyFailedOperations(); err != nil {
800-
finalErrs = append(finalErrs, fmt.Errorf("error getting worthy failed operations: %w", err))
800+
nonCriticalErrs = append(nonCriticalErrs, fmt.Errorf("error getting worthy failed operations: %w", err))
801801
} else if found {
802802
worthyFailedOps = ops
803803
}
@@ -847,33 +847,31 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
847847
NetworkParallelism: networkParallelism,
848848
})
849849

850-
var finalErrs []error
851-
852850
if err := failurePlanExecutor.Execute(ctx); err != nil {
853-
finalErrs = append(finalErrs, fmt.Errorf("error executing failure plan: %w", err))
851+
nonCriticalErrs = append(nonCriticalErrs, fmt.Errorf("error executing failure plan: %w", err))
854852
}
855853

856854
if ops, found, err := failurePlan.WorthyCompletedOperations(); err != nil {
857-
finalErrs = append(finalErrs, fmt.Errorf("error getting worthy completed operations: %w", err))
855+
nonCriticalErrs = append(nonCriticalErrs, fmt.Errorf("error getting worthy completed operations: %w", err))
858856
} else if found {
859857
worthyCompletedOps = append(worthyCompletedOps, ops...)
860858
}
861859

862860
if ops, found, err := failurePlan.WorthyFailedOperations(); err != nil {
863-
finalErrs = append(finalErrs, fmt.Errorf("error getting worthy failed operations: %w", err))
861+
nonCriticalErrs = append(nonCriticalErrs, fmt.Errorf("error getting worthy failed operations: %w", err))
864862
} else if found {
865863
worthyFailedOps = append(worthyFailedOps, ops...)
866864
}
867865

868866
if ops, found, err := failurePlan.WorthyCanceledOperations(); err != nil {
869-
finalErrs = append(finalErrs, fmt.Errorf("error getting worthy canceled operations: %w", err))
867+
nonCriticalErrs = append(nonCriticalErrs, fmt.Errorf("error getting worthy canceled operations: %w", err))
870868
} else if found {
871869
worthyCanceledOps = append(worthyCanceledOps, ops...)
872870
}
873871

874-
return finalErrs
872+
return nonCriticalErrs
875873
}(); len(errs) > 0 {
876-
finalErrs = append(finalErrs, errs...)
874+
nonCriticalErrs = append(nonCriticalErrs, errs...)
877875
}
878876

879877
stdoutTrackerStopCh <- true
@@ -890,14 +888,14 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
890888

891889
if saveDeployReport {
892890
if err := report.Save(deployReportPath); err != nil {
893-
finalErrs = append(finalErrs, fmt.Errorf("error saving deploy report: %w", err))
891+
nonCriticalErrs = append(nonCriticalErrs, fmt.Errorf("error saving deploy report: %w", err))
894892
}
895893
}
896894

897-
if planExecutionErr != nil {
898-
return utls.Multierrorf("failed release %q (namespace: %q)", finalErrs, releaseName, releaseNamespace.Name())
899-
} else if len(finalErrs) > 0 {
900-
return utls.Multierrorf("succeeded release %q (namespace: %q), but errors encountered", finalErrs, releaseName, releaseNamespace.Name())
895+
if len(criticalErrs) > 0 {
896+
return utls.Multierrorf("failed release %q (namespace: %q)", append(criticalErrs, nonCriticalErrs...), releaseName, releaseNamespace.Name())
897+
} else if len(nonCriticalErrs) > 0 {
898+
return utls.Multierrorf("succeeded release %q (namespace: %q), but errors encountered", nonCriticalErrs, releaseName, releaseNamespace.Name())
901899
} else {
902900
log.Default.Info(ctx, color.Style{color.Bold, color.Green}.Render("Succeeded release")+" %q (namespace: %q)", releaseName, releaseNamespace.Name())
903901
return nil

0 commit comments

Comments
 (0)