-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrait_traceable.go
46 lines (39 loc) · 971 Bytes
/
trait_traceable.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
package meep
import (
"bytes"
"io"
)
// Errors with stacks!
type TraitTraceable struct {
Stack Stack
}
type meepTraceable interface {
isMeepTraceable() *TraitTraceable
}
func (m *TraitTraceable) isMeepTraceable() *TraitTraceable { return m }
func (m TraitTraceable) IsStackSet() bool {
return len(m.Stack.Frames) > 0
}
/*
Return the stack of the error formatted as a human readable string:
one frame per line. Each line lists the source file, line number, and
the name of the function.
*/
func (m TraitTraceable) StackString() string {
var buf bytes.Buffer
m.WriteStack(&buf)
return buf.String()
}
// Same job as StackString; use StackString for convenience, use this for performance.
func (m TraitTraceable) WriteStack(w io.Writer) {
if len(m.Stack.Frames) == 0 {
w.Write([]byte("stack info not tracked"))
return
}
for _, fr := range m.Stack.Frames {
//w.Write(tab)
w.Write([]byte("·> "))
w.Write([]byte(fr.String()))
w.Write(br)
}
}