1// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package xerrors_test
6
7import (
8	"fmt"
9
10	"golang.org/x/xerrors"
11)
12
13type MyError2 struct {
14	Message string
15	frame   xerrors.Frame
16}
17
18func (m *MyError2) Error() string {
19	return m.Message
20}
21
22func (m *MyError2) Format(f fmt.State, c rune) { // implements fmt.Formatter
23	xerrors.FormatError(m, f, c)
24}
25
26func (m *MyError2) FormatError(p xerrors.Printer) error { // implements xerrors.Formatter
27	p.Print(m.Message)
28	if p.Detail() {
29		m.frame.Format(p)
30	}
31	return nil
32}
33
34func ExampleFormatError() {
35	err := &MyError2{Message: "oops", frame: xerrors.Caller(1)}
36	fmt.Printf("%v\n", err)
37	fmt.Println()
38	fmt.Printf("%+v\n", err)
39}
40