-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
93 lines (76 loc) · 2.27 KB
/
errors.go
File metadata and controls
93 lines (76 loc) · 2.27 KB
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
88
89
90
91
92
93
package protopatch
import (
"errors"
"fmt"
"github.com/daishe/protopatch/internal/protoops"
)
var (
ErrAccessToNonContainer = errors.New("connot descend into specified key; attempted to access a sub-value in an entity that is not a message, list or map")
ErrAppendToNonList = errors.New("connot append to non list field")
ErrInsertToNonList = errors.New("connot insert to non list field")
// ErrDeleteNonKey = errors.New("connot delete non key value")
ErrMutationOfReadOnlyValue = errors.New("connot mutate read-only value")
ErrMismatchingType = protoops.ErrMismatchingType
)
type ErrNotFound struct {
Kind string // "field", "index" or "key"
Value string
}
func (e ErrNotFound) Error() string {
if e.Kind == "" {
return fmt.Sprintf("%q not found", e.Value)
}
return fmt.Sprintf("%s %q not found", e.Kind, e.Value)
}
type ErrOperationFailed struct {
Op string
Cause error
}
func newSetFailure(cause error) ErrOperationFailed {
return ErrOperationFailed{Op: "set", Cause: cause}
}
func newAppendFailure(cause error) ErrOperationFailed {
return ErrOperationFailed{Op: "append", Cause: cause}
}
func newInsertFailure(cause error) ErrOperationFailed {
return ErrOperationFailed{Op: "insert", Cause: cause}
}
func (e ErrOperationFailed) Error() string {
if e.Op == "" {
return fmt.Sprintf("operation failed: %s", e.Cause.Error())
}
return fmt.Sprintf("cannot %s: %s", e.Op, e.Cause.Error())
}
func (e ErrOperationFailed) Unwrap() error {
return e.Cause
}
// type ErrSwapMissmatchingType struct {
// FirstPath string
// SecondPath string
// }
// func (e ErrSwapMissmatchingType) Error() string {
// return fmt.Sprintf("cannot swap %q with missmatching type %q", e.FirstPath, e.SecondPath)
// }
type ErrInPath struct {
Path string
Cause error
}
func NewErrInPath(path string, err error) error {
if err == nil {
return nil
}
if pe, ok := err.(ErrInPath); ok { // updat path only on direct sub path error, do not use errors.As
pe.Path = string(Path(path).Join(Path(pe.Path)))
return pe
}
return ErrInPath{Path: path, Cause: err}
}
func (e ErrInPath) Error() string {
if e.Path == "" {
return e.Cause.Error()
}
return fmt.Sprintf("proto path %q: %s", e.Path, e.Cause.Error())
}
func (e ErrInPath) Unwrap() error {
return e.Cause
}