Hey.

I am looking at the error wrapping of 1.13-beta at the moment to figure out 
best practices on error handling with this new capability.

My question now is:
If I want to propagate errors up some layers I don't know how to wrap 
additional errors on the path up.

as an example:

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)
}



Any idea or best practices to propagate multiple errors up the stack?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0c09fd82-79ef-4a66-be0c-3401681af371%40googlegroups.com.

Reply via email to