-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpost_execute_error.go
87 lines (68 loc) · 1.62 KB
/
post_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package hype
import (
"encoding/json"
"errors"
"fmt"
"path/filepath"
"strings"
)
type PostExecuteError struct {
Err error
Document *Document
Filename string
OrigErr error
Root string
PostExecuter any
}
func (pee PostExecuteError) MarshalJSON() ([]byte, error) {
mm := map[string]any{
"document": pee.Document,
"error": errForJSON(pee.Err),
"filename": pee.Filename,
"origal_error": errForJSON(pee.OrigErr),
"post_executer": toType(pee.PostExecuter),
"root": pee.Root,
"type": toType(pee),
}
return json.MarshalIndent(mm, "", " ")
}
func (e PostExecuteError) Error() string {
sb := &strings.Builder{}
var lines []string
fp := filepath.Join(e.Root, e.Filename)
if len(fp) > 0 {
lines = append(lines, fmt.Sprintf("filepath: %s", fp))
}
if e.Document != nil && len(e.Document.Title) > 0 {
lines = append(lines, fmt.Sprintf("document: %s", e.Document.Title))
}
if e.Err != nil {
lines = append(lines, fmt.Sprintf("post execute error: %s", e.Err))
}
if e.OrigErr != nil {
lines = append(lines, fmt.Sprintf("original error: %s", e.OrigErr))
}
sb.WriteString(strings.Join(lines, "\n"))
s := sb.String()
return strings.TrimSpace(s)
}
func (e PostExecuteError) Unwrap() error {
if _, ok := e.Err.(unwrapper); ok {
return errors.Unwrap(e.Err)
}
return e.Err
}
func (e PostExecuteError) As(target any) bool {
ex, ok := target.(*PostExecuteError)
if !ok {
return false
}
(*ex) = e
return true
}
func (e PostExecuteError) Is(target error) bool {
if _, ok := target.(PostExecuteError); ok {
return true
}
return false
}