-
Notifications
You must be signed in to change notification settings - Fork 0
/
printer.go
48 lines (38 loc) · 1.07 KB
/
printer.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package pperr
import (
"fmt"
"io"
)
type Printer func(w io.Writer, err error, frames, parent Frames)
var DefaultIndent = "\t"
var DefaultPrinterWithIndent = func(w io.Writer, err error, frames, parent Frames, indent string) {
fmt.Fprintf(w, "%T: %s\n", err, err.Error())
if frames != nil {
if parent != nil {
frames = frames.Exclude(parent)
}
for _, f := range frames {
fmt.Fprintln(w, indent+f.Name)
fmt.Fprintf(w, "%s%s%s:%d\n", indent, indent, f.File, f.Line)
}
}
}
var PrinterWithoutMessage = func(w io.Writer, _ error, frames, parent Frames) {
if frames != nil {
if parent != nil {
frames = frames.Exclude(parent)
}
for _, f := range frames {
fmt.Fprintln(w, f.Name)
fmt.Fprintf(w, "\t%s:%d\n", f.File, f.Line)
}
}
}
var DefaultPrinter Printer = func(w io.Writer, err error, frames, parent Frames) {
DefaultPrinterWithIndent(w, err, frames, parent, DefaultIndent)
}
func NewPrinterWithIndent(indent string) Printer {
return func(w io.Writer, err error, frames, parent Frames) {
DefaultPrinterWithIndent(w, err, frames, parent, indent)
}
}