This is the right way. What is the issue you are facing ? See 
https://tip.golang.org/pkg/errors/ for more info.

You can check for Layer1Error and Layer2Error using the Is function

errors.Is(err, Layer1Error)

errors.Is(err, Layer2Error)

On Friday, 9 August 2019 19:09:24 UTC+5:30, Alex wrote:
>
> Sorry, mixed things up in the code with layer1 and layer2... 
>
>
> 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)
> }
>
>
>

-- 
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/8a149bf3-fa6b-41b3-94b3-517f41dd373b%40googlegroups.com.

Reply via email to