/
execute_error.go
57 lines (46 loc) · 960 Bytes
/
execute_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
49
50
51
52
53
54
55
56
57
package hype
import (
"encoding/json"
"errors"
)
type ExecuteError struct {
Err error
Contents []byte
Document *Document
Filename string
Root string
}
func (pe ExecuteError) MarshalJSON() ([]byte, error) {
mm := map[string]any{
"contents": string(pe.Contents),
"document": pe.Document,
"error": errForJSON(pe.Err),
"filename": pe.Filename,
"root": pe.Root,
"type": toType(pe),
}
return json.MarshalIndent(mm, "", " ")
}
func (pe ExecuteError) Error() string {
return toError(pe)
}
func (pe ExecuteError) Unwrap() error {
if _, ok := pe.Err.(unwrapper); ok {
return errors.Unwrap(pe.Err)
}
return pe.Err
}
func (pe ExecuteError) As(target any) bool {
ex, ok := target.(*ExecuteError)
if !ok {
return errors.As(pe.Err, target)
}
(*ex) = pe
return true
}
func (pe ExecuteError) Is(target error) bool {
if _, ok := target.(ExecuteError); ok {
return true
}
return errors.Is(pe.Err, target)
}