From 27b96c9403b92888fd40b912786bf465dc51e323 Mon Sep 17 00:00:00 2001 From: Lorenz Brun Date: Fri, 14 May 2021 14:09:40 +0200 Subject: [PATCH] Make Keberos result codes available from errors --- v8/krberror/error.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/v8/krberror/error.go b/v8/krberror/error.go index 01c6d990..548f9735 100644 --- a/v8/krberror/error.go +++ b/v8/krberror/error.go @@ -21,8 +21,9 @@ const ( // Krberror is an error type for gokrb5 type Krberror struct { - RootCause string - EText []string + RootCause string + EText []string + innerError error } // Error function to implement the error interface. @@ -35,6 +36,11 @@ func (e *Krberror) Add(et string, s string) { e.EText = append([]string{fmt.Sprintf("%s: %s", et, s)}, e.EText...) } +// Unwrap returns the inner error (if any) +func (e Krberror) Unwrap() error { + return e.innerError +} + // New creates a new instance of Krberror. func New(et, s string) Krberror { return Krberror{ @@ -49,7 +55,9 @@ func Errorf(err error, et, format string, a ...interface{}) Krberror { e.Add(et, fmt.Sprintf(format, a...)) return e } - return NewErrorf(et, format+": %s", append(a, err)...) + e := NewErrorf(et, format+": %s", append(a, err)...) + e.innerError = err + return e } // NewErrorf creates a new Krberror from a formatted string.