feat: add support for multierror when exiting triggers

This commit is contained in:
Jose Diaz-Gonzalez
2024-01-20 06:56:14 -05:00
parent d40b264a40
commit 6908177095
37 changed files with 121 additions and 1 deletions

View File

@@ -6,6 +6,8 @@ import (
"strconv"
"strings"
"sync"
"github.com/hashicorp/go-multierror"
)
// ErrWithExitCode wraps error and exposes an ExitCode method
@@ -54,7 +56,17 @@ func LogFail(text string) {
// LogFailWithError is the failure log formatter
// prints text to stderr and exits with the specified exit code
func LogFailWithError(err error) {
fmt.Fprintln(os.Stderr, fmt.Sprintf(" ! %s", err.Error()))
if err == nil {
return
}
if merr, ok := err.(*multierror.Error); ok {
for _, e := range merr.Errors {
fmt.Fprintf(os.Stderr, " ! %s\n", e.Error())
}
} else {
fmt.Fprintf(os.Stderr, " ! %s\n", err.Error())
}
if errExit, ok := err.(ErrWithExitCode); ok {
os.Exit(errExit.ExitCode())
}