var ( Layer1Error = errors.New("some error on layer 1") Layer2Error = errors.New("some error on layer 2"))
func main() { err := callLayer1Function()
// do something with error}
func callLayer1Function() error { err := callLayer2Function()
// how to not lose layer2 error but also append a new layer1 error ? // this does not work, since you fully lose layer1 error // with pkg/err return fmt.Errorf("some specific layer 2 error message: %w", Layer2Error)}
func callLayer2Function() error { // wrap an error of Layer1 here return fmt.Errorf("some specific layer1 error message: %w", Layer1Error)}
var ( Layer1Error = errors.New("some error on layer 1") Layer2Error = errors.New("some error on layer 2"))
func main() { err := callLayer1Function()
// do something with error}
func callLayer1Function() error { err := callLayer2Function()
// how to not lose layer2 error but also append a new layer1 error ? // this does not work, since you fully lose layer1 error // with pkg/err
return fmt.Errorf("some specific layer 1 error message: %w", Layer1Error)}
func callLayer2Function() error { // wrap an error of Layer2 here return fmt.Errorf("some specific layer2 error message: %w", Layer2Error)}
type myError struct {
msg string // some additional msg
current error // Layer1Error
cause error // Layer2Error
}
var (
Layer1Error = errors.New("some error on layer 1: %w")
Layer2Error = errors.New("some error on layer 2")
)
func callLayer1Function() error {
err := callLayer2Function()
// how to not lose layer2 error but also append a new layer1 error ?
// this does not work, since you fully lose layer1 error
// with pkg/err
return fmt.Errorf(Layer1Error.Error(), Layer1Error)
}
Layer1Error
` as an error, it can be juts a string.