forked from pkg/errors
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split up into separate pakages (#50)
This is a re-structuring. The functionality remains the same. a base stackfmt package. This package is just for stack traces and does not do anything with errors. A separate slogerr package for those looking to add structured errors. An errwrap package for wrapping and unwrapping errors Maintain the existing errors package. This is designed as a replacement for the existing errors package that introduces wrapping with stack traces The errors package will re-export some items from other packages. However, it is exporting much less overall.
- Loading branch information
Showing
26 changed files
with
1,519 additions
and
1,060 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package errors | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
) | ||
|
||
func formatterPlusV(s fmt.State, verb rune, err error) { | ||
if f, ok := err.(fmt.Formatter); ok { | ||
f.Format(s, verb) | ||
} else { | ||
fmt.Fprintf(s, "%+v", err) | ||
} | ||
} | ||
|
||
type unwrapper interface { | ||
Unwrap() error | ||
} | ||
|
||
type unwraps interface { | ||
Unwrap() []error | ||
} | ||
|
||
type errorUnwrap interface { | ||
Unwrap() error | ||
// ErrorNoUnwrap is the error message component of the wrapping | ||
// It will be a prefix of Error() | ||
// If there is no message in the wrapping then this can return an empty string | ||
ErrorNoUnwrap() string | ||
} | ||
|
||
func isNil(err error) bool { | ||
if err == nil { | ||
return true | ||
} | ||
|
||
v := reflect.ValueOf(err) | ||
k := v.Kind() | ||
switch k { | ||
case reflect.Pointer, reflect.UnsafePointer, reflect.Interface: | ||
return v.IsNil() | ||
case reflect.Slice, reflect.Array, reflect.Map: | ||
return v.IsNil() || v.Len() == 0 | ||
} | ||
|
||
return false | ||
} |
Oops, something went wrong.