github.com/haraldrudell/parl@v0.4.176/perrors/errorglue/related-error.go (about) 1 /* 2 © 2021–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package errorglue 7 8 // relatedError implements additional associated errors separate from the error chain. 9 // Associated errors allows for a function to return a single error value containing multiple error instances. 10 // An error chain otherwise augments a single error with additional information. 11 // An error list is commonly built using error116.AppendError(err, err2) error 12 type relatedError struct { 13 ErrorChain // errorList implements error chain, ie. rich data associated with a single error 14 e error // e is an additional error 15 } 16 17 var _ error = &relatedError{} // relatedError behaves like an error 18 var _ Wrapper = &relatedError{} // relatedError is an error chain 19 var _ RelatedError = &relatedError{} // relatedError has an associated error 20 21 func NewRelatedError(err, err2 error) (e2 error) { 22 return &relatedError{*newErrorChain(err), err2} 23 } 24 25 func (et *relatedError) AssociatedError() (err error) { 26 if et == nil { 27 return 28 } 29 return et.e 30 }