-
Notifications
You must be signed in to change notification settings - Fork 731
/
errors.go
48 lines (37 loc) 路 1011 Bytes
/
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
package schema
import (
"errors"
"fmt"
"github.com/open-policy-agent/gatekeeper/v3/pkg/util"
)
// ErrNilMutator reports that a method which expected an actual Mutator was
// a nil pointer.
const ErrNilMutator = util.Error("attempted to add nil mutator")
func NewErrConflictingSchema(ids IDSet) error {
return ErrConflictingSchema{Conflicts: ids}
}
const ErrConflictingSchemaType = "ErrConflictingSchema"
// ErrConflictingSchema reports that adding a Mutator to the DB resulted in
// conflicting implicit schemas.
type ErrConflictingSchema struct {
Conflicts IDSet
}
func (e ErrConflictingSchema) Error() string {
return fmt.Sprintf("the following mutators have conflicting schemas: %v",
e.Conflicts.String())
}
func (e ErrConflictingSchema) Is(other error) bool {
var o ErrConflictingSchema
if !errors.As(other, &o) {
return false
}
if len(e.Conflicts) != len(o.Conflicts) {
return false
}
for id := range e.Conflicts {
if !o.Conflicts[id] {
return false
}
}
return true
}