-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patherrors.go
73 lines (60 loc) · 1.85 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package javascript
import (
"github.com/dop251/goja"
"github.com/stephane-martin/skewer/utils/eerrors"
)
func ErrorUnknownFormat(format string) error {
return DecodingError(eerrors.Errorf("Unknown decoder: '%s'", format))
}
func InvalidTopicError(topic string) error {
return DecodingError(
eerrors.Errorf("The topic name is invalid: '%s'", topic),
)
}
func DecodingError(err error) error {
return eerrors.WithTypes(
eerrors.Wrap(err, "Error decoding message"),
"Decoding",
)
}
func jsvmError(err error) error {
return eerrors.WithTypes(err, "Javascript")
}
func objectNotFoundError(obj string) error {
return jsvmError(eerrors.Errorf("Object was not found in the JS VM: '%s'", obj))
}
func notAFunctionError(obj string) error {
return jsvmError(eerrors.Errorf("The object is not a JS function: '%s'", obj))
}
func jsExceptionError(exc *goja.Exception, funcname string) error {
return jsvmError(
eerrors.Errorf(
"A JS exception happened when executing the JS function '%s': %s",
funcname, exc.String(),
),
)
}
func executingJSError(err error, funcname string) error {
return jsvmError(eerrors.Wrapf(err, "An unexpected error happened when executing the JS function '%s'", funcname))
}
func executingJSErrorFactory(err error, funcname string) error {
if jsexc, ok := err.(*goja.Exception); ok {
return jsExceptionError(jsexc, funcname)
}
return executingJSError(err, funcname)
}
func go2jsError(err error) error {
return jsvmError(eerrors.Wrap(err, "Error converting a Go variable to JS"))
}
func js2goError(err error) error {
return jsvmError(eerrors.Wrap(err, "Error converting a JS variable to Go"))
}
func jsDecodingError(msg string, decoderName string) error {
return eerrors.WithTypes(
eerrors.Errorf(
"The provided JS parser '%s' could not parse the following message: %s",
decoderName, msg,
),
"Decoding", "Javascript",
)
}