mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-02 06:16:08 -04:00
deps: replace multierr with native errors.Join
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
parent
955316c661
commit
12c866bcb9
32 changed files with 173 additions and 159 deletions
|
@ -10,7 +10,6 @@ import (
|
|||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
@ -25,22 +24,27 @@ import (
|
|||
"github.com/edgelesssys/constellation/v2/internal/versionsapi"
|
||||
ut "github.com/go-playground/universal-translator"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"go.uber.org/multierr"
|
||||
"golang.org/x/mod/semver"
|
||||
)
|
||||
|
||||
// DisplayValidationErrors shows all validation errors inside configError as one formatted string.
|
||||
func DisplayValidationErrors(errWriter io.Writer, configError error) error {
|
||||
errs := multierr.Errors(configError)
|
||||
if errs != nil {
|
||||
fmt.Fprintln(errWriter, "Problems validating config file:")
|
||||
for _, err := range errs {
|
||||
fmt.Fprintln(errWriter, "\t"+err.Error())
|
||||
}
|
||||
fmt.Fprintln(errWriter, "Fix the invalid entries or generate a new configuration using `constellation config generate`")
|
||||
return errors.New("invalid configuration")
|
||||
// ValidationError occurs when the validation of a config fails.
|
||||
// It contains a list of errors that occurred during validation.
|
||||
type ValidationError struct {
|
||||
validationErrMsgs []string
|
||||
}
|
||||
|
||||
func (e *ValidationError) Error() string {
|
||||
return "invalid configuration"
|
||||
}
|
||||
|
||||
// LongMessage prints the errors that occurred during validation in a verbose and user friendly way.
|
||||
func (e *ValidationError) LongMessage() string {
|
||||
msg := "Problems validating config file:\n"
|
||||
for _, ve := range e.validationErrMsgs {
|
||||
msg += fmt.Sprintf("\t%s\n", ve)
|
||||
}
|
||||
return nil
|
||||
msg += "Fix the invalid entries or generate a new configuration using `constellation config generate`"
|
||||
return msg
|
||||
}
|
||||
|
||||
func registerInvalidK8sVersionError(ut ut.Translator) error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue