Files
  • main.go
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package main

import (
	"errors"
	"fmt"

	pkgerrors "github.com/pkg/errors"
)

// :show start

func wrappedError() error {
	err := errors.New("Original error")
	// create a new error value which wraps original err and
	// adds calls tack
	return pkgerrors.WithStack(err)
}

func main() {
	// %+v prints original error add callstack
	fmt.Printf("err: %+v\n\n", wrappedError())

	// errors created with pkg/errors include callstack by default
	fmt.Printf("err: %+v\n", pkgerrors.New("error created with pkg/errors"))
}

// :show end
go version go1.9.4 linux/amd64