@kjk1/

gobook error handling add callstack

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.7656060969589809","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"CnBhY2thZ2UgbWFpbgoKaW1wb3J0ICgKCSJlcnJvcnMiCgkiZm10IgoKCXBrZ2Vycm9ycyAiZ2l0aHViLmNvbS9wa2cvZXJyb3JzIgopCgovLyA6c2hvdyBzdGFydAoKZnVuYyB3cmFwcGVkRXJyb3IoKSBlcnJvciB7CgllcnIgOj0gZXJyb3JzLk5ldygiT3JpZ2luYWwgZXJyb3IiKQoJLy8gY3JlYXRlIGEgbmV3IGVycm9yIHZhbHVlIHdoaWNoIHdyYXBzIG9yaWdpbmFsIGVyciBhbmQKCS8vIGFkZHMgY2FsbHMgdGFjawoJcmV0dXJuIHBrZ2Vycm9ycy5XaXRoU3RhY2soZXJyKQp9CgpmdW5jIG1haW4oKSB7CgkvLyAlK3YgcHJpbnRzIG9yaWdpbmFsIGVycm9yIGFkZCBjYWxsc3RhY2sKCWZtdC5QcmludGYoImVycjogJSt2XG5cbiIsIHdyYXBwZWRFcnJvcigpKQoKCS8vIGVycm9ycyBjcmVhdGVkIHdpdGggcGtnL2Vycm9ycyBpbmNsdWRlIGNhbGxzdGFjayBieSBkZWZhdWx0CglmbXQuUHJpbnRmKCJlcnI6ICUrdlxuIiwgcGtnZXJyb3JzLk5ldygiZXJyb3IgY3JlYXRlZCB3aXRoIHBrZy9lcnJvcnMiKSkKfQoKLy8gOnNob3cgZW5k"},"asBuffer":null},"loaded":true}}
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