...

Source file src/sigs.k8s.io/kustomize/kyaml/errors/errors.go

Documentation: sigs.k8s.io/kustomize/kyaml/errors

     1  // Copyright 2019 The Kubernetes Authors.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  // Package errors provides libraries for working with the go-errors/errors library.
     5  package errors
     6  
     7  import (
     8  	"fmt"
     9  
    10  	goerrors "github.com/go-errors/errors"
    11  )
    12  
    13  // Wrap returns err wrapped in a go-error.  If err is nil, returns nil.
    14  func Wrap(err interface{}) error {
    15  	if err == nil {
    16  		return nil
    17  	}
    18  	return goerrors.Wrap(err, 1)
    19  }
    20  
    21  // WrapPrefixf returns err wrapped in a go-error with a message prefix.  If err is nil, returns nil.
    22  func WrapPrefixf(err interface{}, msg string, args ...interface{}) error {
    23  	if err == nil {
    24  		return nil
    25  	}
    26  	return goerrors.WrapPrefix(err, fmt.Sprintf(msg, args...), 1)
    27  }
    28  
    29  // Errorf returns a new go-error.
    30  func Errorf(msg string, args ...interface{}) error {
    31  	return goerrors.Wrap(fmt.Errorf(msg, args...), 1)
    32  }
    33  
    34  // As finds the targeted error in any wrapped error.
    35  func As(err error, target interface{}) bool {
    36  	return goerrors.As(err, target)
    37  }
    38  
    39  // Is detects whether the error is equal to a given error.
    40  func Is(err error, target error) bool {
    41  	return goerrors.Is(err, target)
    42  }
    43  
    44  // GetStack returns a stack trace for the error if it has one
    45  func GetStack(err error) string {
    46  	if e, ok := err.(*goerrors.Error); ok {
    47  		return string(e.Stack())
    48  	}
    49  	return ""
    50  }
    51  

View as plain text