-
Notifications
You must be signed in to change notification settings - Fork 267
/
errors.go
164 lines (136 loc) · 4.66 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package graph
import (
"errors"
"fmt"
"github.com/rs/zerolog"
"github.com/authzed/spicedb/internal/sharederrors"
)
// ErrRequestCanceled occurs when a request has been canceled.
type ErrRequestCanceled struct {
error
}
// NewRequestCanceledErr constructs a new request was canceled error.
func NewRequestCanceledErr() error {
return ErrRequestCanceled{
error: errors.New("request canceled"),
}
}
// ErrCheckFailure occurs when check failed in some manner. Note this should not apply to
// namespaces and relations not being found.
type ErrCheckFailure struct {
error
}
// NewCheckFailureErr constructs a new check failed error.
func NewCheckFailureErr(baseErr error) error {
return ErrCheckFailure{
error: fmt.Errorf("error performing check: %w", baseErr),
}
}
// ErrExpansionFailure occurs when expansion failed in some manner. Note this should not apply to
// namespaces and relations not being found.
type ErrExpansionFailure struct {
error
}
// NewExpansionFailureErr constructs a new expansion failed error.
func NewExpansionFailureErr(baseErr error) error {
return ErrExpansionFailure{
error: fmt.Errorf("error performing expand: %w", baseErr),
}
}
// ErrAlwaysFail is returned when an internal error leads to an operation
// guaranteed to fail.
type ErrAlwaysFail struct {
error
}
// NewAlwaysFailErr constructs a new always fail error.
func NewAlwaysFailErr() error {
return ErrAlwaysFail{
error: errors.New("always fail"),
}
}
// ErrRelationNotFound occurs when a relation was not found under a namespace.
type ErrRelationNotFound struct {
error
namespaceName string
relationName string
}
// NamespaceName returns the name of the namespace in which the relation was not found.
func (err ErrRelationNotFound) NamespaceName() string {
return err.namespaceName
}
// NotFoundRelationName returns the name of the relation not found.
func (err ErrRelationNotFound) NotFoundRelationName() string {
return err.relationName
}
func (err ErrRelationNotFound) MarshalZerologObject(e *zerolog.Event) {
e.Err(err.error).Str("namespace", err.namespaceName).Str("relation", err.relationName)
}
// DetailsMetadata returns the metadata for details for this error.
func (err ErrRelationNotFound) DetailsMetadata() map[string]string {
return map[string]string{
"definition_name": err.namespaceName,
"relation_or_permission_name": err.relationName,
}
}
// NewRelationNotFoundErr constructs a new relation not found error.
func NewRelationNotFoundErr(nsName string, relationName string) error {
return ErrRelationNotFound{
error: fmt.Errorf("relation/permission `%s` not found under definition `%s`", relationName, nsName),
namespaceName: nsName,
relationName: relationName,
}
}
var _ sharederrors.UnknownRelationError = ErrRelationNotFound{}
// ErrRelationMissingTypeInfo defines an error for when type information is missing from a relation
// during a lookup.
type ErrRelationMissingTypeInfo struct {
error
namespaceName string
relationName string
}
// NamespaceName returns the name of the namespace in which the relation was found.
func (err ErrRelationMissingTypeInfo) NamespaceName() string {
return err.namespaceName
}
// RelationName returns the name of the relation missing type information.
func (err ErrRelationMissingTypeInfo) RelationName() string {
return err.relationName
}
func (err ErrRelationMissingTypeInfo) MarshalZerologObject(e *zerolog.Event) {
e.Err(err.error).Str("namespace", err.namespaceName).Str("relation", err.relationName)
}
// DetailsMetadata returns the metadata for details for this error.
func (err ErrRelationMissingTypeInfo) DetailsMetadata() map[string]string {
return map[string]string{
"definition_name": err.namespaceName,
"relation_name": err.relationName,
}
}
// NewRelationMissingTypeInfoErr constructs a new relation not missing type information error.
func NewRelationMissingTypeInfoErr(nsName string, relationName string) error {
return ErrRelationMissingTypeInfo{
error: fmt.Errorf("relation/permission `%s` under definition `%s` is missing type information", relationName, nsName),
namespaceName: nsName,
relationName: relationName,
}
}
// ErrInvalidArgument occurs when a request sent has an invalid argument.
type ErrInvalidArgument struct {
error
}
// NewErrInvalidArgument constructs a request sent has an invalid argument.
func NewErrInvalidArgument(baseErr error) error {
return ErrInvalidArgument{
error: baseErr,
}
}
// ErrUnimplemented is returned when some functionality is not yet supported.
type ErrUnimplemented struct {
error
}
// NewUnimplementedErr constructs a new unimplemented error.
func NewUnimplementedErr(baseErr error) error {
return ErrUnimplemented{
error: baseErr,
}
}