-
Notifications
You must be signed in to change notification settings - Fork 3
/
errors.go
48 lines (39 loc) · 981 Bytes
/
errors.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 main
import (
"fmt"
"net/http"
"runtime"
)
type syntaxErr struct {
s string
}
func (e *syntaxErr) Error() string {
return e.s
}
func prependInfo(err error, file string, line int, ok bool) error {
if ok {
return fmt.Errorf("%s:%d => %s", file, line, err)
} else {
return fmt.Errorf("%s (failed getting runtime info)", err)
}
}
func funcName() string {
pc, _, _, _ := runtime.Caller(1)
return runtime.FuncForPC(pc).Name()
}
// func dumpStack() {
// buf := make([]byte, 1<<16)
// runtime.Stack(buf, true)
// fmt.Printf("%s", buf)
// }
// func newErrWithInfo(s string) error {
// _, file, line, ok := runtime.Caller(1)
// return prependInfo(errors.New(s), file, line, ok)
// }
// func errWithInfo(err error) error {
// _, file, line, ok := runtime.Caller(1)
// return prependInfo(err, file, line, ok)
// }
func httpGenericErr(w http.ResponseWriter) {
http.Error(w, "Something went wrong, check the logs", http.StatusInternalServerError)
}