-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
err.go
49 lines (39 loc) · 1.08 KB
/
err.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
49
package web
import (
"fmt"
//"log"
"runtime"
"bytes"
"os"
)
// type errorType struct {
// log
// }
func error(f string, args ...interface{}) {
calldepth := 5
_, file, line, ok := runtime.Caller(calldepth)
if !ok {
file = "???"
line = 0
}
msg := bytes.NewBuffer(make([]byte, 0, 64))
fmt.Fprintf(msg, "%s:%d: ", file, line)
fmt.Fprintf(msg, f, args...)
panic(msg.String())
}
func newError(msg string) os.Error {
stack := make([]uintptr, 30)
n := runtime.Callers(0, stack)
stack = stack[0:n]
str := bytes.NewBuffer(make([]byte, 0, 256))
fmt.Fprintf(str, "%s\n", msg)
for i := range stack {
pc := stack[len(stack)-i-1]
f := runtime.FuncForPC(pc)
if f != nil {
file, line := f.FileLine(pc)
fmt.Fprintf(str, "%s:%d: %s\n", file, line, f.Name())
}
}
return os.NewError(str.String())
}