github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/internal/dispatch/graph/errors.go (about) 1 package graph 2 3 import ( 4 "fmt" 5 6 "github.com/rs/zerolog" 7 ) 8 9 // ErrNamespaceNotFound occurs when a namespace was not found. 10 type ErrNamespaceNotFound struct { 11 error 12 namespaceName string 13 } 14 15 // NotFoundNamespaceName returns the name of the namespace that was not found. 16 func (err ErrNamespaceNotFound) NotFoundNamespaceName() string { 17 return err.namespaceName 18 } 19 20 // MarshalZerologObject implements zerolog.LogObjectMarshaler 21 func (err ErrNamespaceNotFound) MarshalZerologObject(e *zerolog.Event) { 22 e.Err(err.error).Str("namespace", err.namespaceName) 23 } 24 25 // DetailsMetadata returns the metadata for details for this error. 26 func (err ErrNamespaceNotFound) DetailsMetadata() map[string]string { 27 return map[string]string{ 28 "definition_name": err.namespaceName, 29 } 30 } 31 32 // NewNamespaceNotFoundErr constructs a new namespace not found error. 33 func NewNamespaceNotFoundErr(nsName string) error { 34 return ErrNamespaceNotFound{ 35 error: fmt.Errorf("object definition `%s` not found", nsName), 36 namespaceName: nsName, 37 } 38 } 39 40 // ErrRelationNotFound occurs when a relation was not found under a namespace. 41 type ErrRelationNotFound struct { 42 error 43 namespaceName string 44 relationName string 45 } 46 47 // NamespaceName returns the name of the namespace in which the relation was not found. 48 func (err ErrRelationNotFound) NamespaceName() string { 49 return err.namespaceName 50 } 51 52 // NotFoundRelationName returns the name of the relation not found. 53 func (err ErrRelationNotFound) NotFoundRelationName() string { 54 return err.relationName 55 } 56 57 // MarshalZerologObject implements zerolog.LogObjectMarshaler 58 func (err ErrRelationNotFound) MarshalZerologObject(e *zerolog.Event) { 59 e.Err(err.error).Str("namespace", err.namespaceName).Str("relation", err.relationName) 60 } 61 62 // DetailsMetadata returns the metadata for details for this error. 63 func (err ErrRelationNotFound) DetailsMetadata() map[string]string { 64 return map[string]string{ 65 "definition_name": err.namespaceName, 66 "relation_or_permission_name": err.relationName, 67 } 68 } 69 70 // NewRelationNotFoundErr constructs a new relation not found error. 71 func NewRelationNotFoundErr(nsName string, relationName string) error { 72 return ErrRelationNotFound{ 73 error: fmt.Errorf("relation/permission `%s` not found under definition `%s`", relationName, nsName), 74 namespaceName: nsName, 75 relationName: relationName, 76 } 77 }