github.com/haraldrudell/parl@v0.4.176/perrors/errorglue/error-glue.go (about) 1 /* 2 © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 // Package errorglue contains non-essential error declarations 7 package errorglue 8 9 import "github.com/haraldrudell/parl/pruntime" 10 11 // ChainStringer obntain s a comprehensive string representation of an error chain. 12 // formats used are DefaultFormat ShortFormat LongFormat ShortSuffix LongSuffix 13 type ChainStringer interface { 14 // ChainString is used by ChainStringer() to obtain comprehensive 15 // string representations of errors. 16 // The argument isIgnore() is used to avoid printing cyclic error values. 17 // If a ChainStringer pointer receiver gets a nil value, the empty string is returned. 18 // ChainString() obtains a string representation of the errors in its chain. 19 // Rich errors implement either ChainStringer or fmt.Formatter 20 ChainString(format CSFormat) string 21 } 22 23 // Wrapper is an interface indicating error-chain capabilities. 24 // It is not public in errors package 25 type Wrapper interface { 26 Unwrap() error // Unwrap returns the next error in the chain or nil 27 } 28 29 // ErrorHasData enrichens an error with key and value strings 30 type ErrorHasData interface { 31 KeyValue() (key, value string) 32 } 33 34 // RelatedError enrichens an error with an enclosed additional error value 35 type RelatedError interface { 36 AssociatedError() (error error) 37 } 38 39 // ErrorHasCode allows an error to classify itself 40 type ErrorHasCode interface { 41 // Check if this error claims a particular Linux errno, an int 42 IsErrno(errno int) (hasErrno bool) 43 // ErrorCode determines if this error claims code, a string 44 ErrorCode(code string) (hasCode bool) 45 // ErrorCodes returns codes that this error claims, some are numeric strings mapping to an errno 46 ErrorCodes(codes []string) (has []string) 47 } 48 49 // ErrorCallStacker enrichens an error with a stack trace of code locations 50 type ErrorCallStacker interface { 51 StackTrace() (stack pruntime.Stack) 52 } 53 54 // ErrorStore is a thread-safe store for any number of errors 55 type ErrorStore interface { 56 AddError(err error) (e error) 57 GetError() (e error) 58 InvokeIfError(fn func(err error)) 59 Error() (message string) 60 }