mirror of
https://github.com/containers/podman.git
synced 2025-06-13 19:52:11 +08:00
libpod/runtime: switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of the deprecated github.com/pkg/errors package. [NO NEW TESTS NEEDED] Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
package errorhandling
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -121,3 +121,22 @@ func (e PodConflictErrorModel) Error() string {
|
||||
func (e PodConflictErrorModel) Code() int {
|
||||
return 409
|
||||
}
|
||||
|
||||
// Cause returns the most underlying error for the provided one. There is a
|
||||
// maximum error depth of 100 to avoid endless loops. An additional error log
|
||||
// message will be created if this maximum has reached.
|
||||
func Cause(err error) (cause error) {
|
||||
cause = err
|
||||
|
||||
const maxDepth = 100
|
||||
for i := 0; i <= maxDepth; i++ {
|
||||
res := errors.Unwrap(cause)
|
||||
if res == nil {
|
||||
return cause
|
||||
}
|
||||
cause = res
|
||||
}
|
||||
|
||||
logrus.Errorf("Max error depth of %d reached, cannot unwrap until root cause: %v", maxDepth, err)
|
||||
return cause
|
||||
}
|
||||
|
Reference in New Issue
Block a user