-
Notifications
You must be signed in to change notification settings - Fork 34
/
error.go
48 lines (36 loc) · 1.08 KB
/
error.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 jast
//go:generate bash -c "(egen -i $GOPATH/src/github.com/infobloxopen/themis/pdp/ast/jast/errors.yaml > $GOPATH/src/github.com/infobloxopen/themis/pdp/ast/jast/errors.go) && gofmt -l -s -w $GOPATH/src/github.com/infobloxopen/themis/pdp/ast/jast/errors.go"
import (
"fmt"
"strings"
)
const errorSourcePathSeparator = ">"
type boundError interface {
error
bind(src string)
}
func bindError(err error, src string) boundError {
b, ok := err.(boundError)
if ok {
b.bind(src)
return b
}
return bindError(newExternalError(err), src)
}
func bindErrorf(err error, format string, args ...interface{}) boundError {
return bindError(err, fmt.Sprintf(format, args...))
}
type errorLink struct {
id int
path []string
}
func (e *errorLink) errorf(format string, args ...interface{}) string {
msg := fmt.Sprintf(format, args...)
if len(e.path) > 0 {
return fmt.Sprintf("#%02x (%s): %s", e.id, strings.Join(e.path, errorSourcePathSeparator), msg)
}
return fmt.Sprintf("#%02x: %s", e.id, msg)
}
func (e *errorLink) bind(src string) {
e.path = append([]string{src}, e.path...)
}