mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 10:00:56 +00:00
Improve error handling in kyaml libraries
This commit is contained in:
32
kyaml/errors/errors.go
Normal file
32
kyaml/errors/errors.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package errors provides libraries for working with the go-errors/errors library.
|
||||
package errors
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
goerrors "github.com/go-errors/errors"
|
||||
)
|
||||
|
||||
// Wrap returns err wrapped in a go-error. If err is nil, returns nil.
|
||||
func Wrap(err interface{}) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return goerrors.Wrap(err, 1)
|
||||
}
|
||||
|
||||
// WrapPrefixf returns err wrapped in a go-error with a message prefix. If err is nil, returns nil.
|
||||
func WrapPrefixf(err interface{}, msg string, args ...interface{}) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return goerrors.WrapPrefix(err, fmt.Sprintf(msg, args...), 1)
|
||||
}
|
||||
|
||||
// Errorf returns a new go-error.
|
||||
func Errorf(msg string, args ...interface{}) error {
|
||||
return goerrors.Wrap(fmt.Errorf(msg, args...), 1)
|
||||
}
|
||||
Reference in New Issue
Block a user