-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
post_parse_error.go
60 lines (49 loc) · 1.04 KB
/
post_parse_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
package hype
import (
"encoding/json"
"errors"
)
type PostParseError struct {
Err error
Document *Document
Filename string
OrigErr error
Root string
PostParser any
}
func (ppe PostParseError) MarshalJSON() ([]byte, error) {
mm := map[string]any{
"document": ppe.Document,
"error": toError(ppe.Err),
"filename": ppe.Filename,
"origal_error": toError(ppe.OrigErr),
"post_parser": toType(ppe.PostParser),
"root": ppe.Root,
"type": toType(ppe),
}
return json.MarshalIndent(mm, "", " ")
}
func (ppe PostParseError) Error() string {
b, _ := ppe.MarshalJSON()
return string(b)
}
func (ppe PostParseError) Unwrap() error {
if _, ok := ppe.Err.(unwrapper); ok {
return errors.Unwrap(ppe.Err)
}
return ppe.Err
}
func (ppe PostParseError) As(target any) bool {
ex, ok := target.(*PostParseError)
if !ok {
return false
}
(*ex) = ppe
return true
}
func (ppe PostParseError) Is(target error) bool {
if _, ok := target.(PostParseError); ok {
return true
}
return false
}