Skip to content

Commit

Permalink
Convert step onError from string to "OnErrorType" type
Browse files Browse the repository at this point in the history
Prior to this commit, the step onError field is defined as normal string and the 2 supported string values "continue" and "stopAndFail" are directly used across the codebase. This is error-prone and it introduces maintenance difficulty. This commit updates the onError field to be typed string "OnErrorType", with constants defined for the 2 supported values, and updates all the related references
  • Loading branch information
QuanZhang-William committed Aug 16, 2022
1 parent 795e720 commit 92386df
Show file tree
Hide file tree
Showing 19 changed files with 322 additions and 211 deletions.
7 changes: 4 additions & 3 deletions cmd/entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/containerd/containerd/platforms"
"github.com/tektoncd/pipeline/cmd/entrypoint/subcommands"
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/credentials"
"github.com/tektoncd/pipeline/pkg/credentials/dockercreds"
"github.com/tektoncd/pipeline/pkg/credentials/gitcreds"
Expand Down Expand Up @@ -146,7 +147,7 @@ func main() {
Results: strings.Split(*results, ","),
Timeout: timeout,
BreakpointOnFailure: *breakpointOnFailure,
OnError: *onError,
OnError: v1beta1.OnErrorType(*onError),
StepMetadataDir: *stepMetadataDir,
}

Expand Down Expand Up @@ -175,12 +176,12 @@ func main() {
if status, ok := t.Sys().(syscall.WaitStatus); ok {
checkForBreakpointOnFailure(e, breakpointExitPostFile)
// ignore a step error i.e. do not exit if a container terminates with a non-zero exit code when onError is set to "continue"
if e.OnError != entrypoint.ContinueOnError {
if e.OnError != v1beta1.Continue {
os.Exit(status.ExitStatus())
}
}
// log and exit only if a step error must cause run failure
if e.OnError != entrypoint.ContinueOnError {
if e.OnError != v1beta1.Continue {
log.Fatalf("Error executing command (ExitError): %v", err)
}
default:
Expand Down
Loading

0 comments on commit 92386df

Please sign in to comment.