Skip to content

Commit

Permalink
Move Primary not defined err to client pkg
Browse files Browse the repository at this point in the history
Will be used from the graphql package too shortly
  • Loading branch information
AndrewSisley committed Mar 27, 2024
1 parent a2591f8 commit bd427f3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
9 changes: 9 additions & 0 deletions client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
errFailedToUnmarshalCollection string = "failed to unmarshal collection json"
errOperationNotPermittedOnNamelessCols string = "operation not permitted on nameless collection"
errInvalidJSONPayload string = "invalid JSON payload"
errPrimarySideNotDefined string = "primary side of relation not defined"
)

// Errors returnable from this package.
Expand All @@ -51,6 +52,7 @@ var (
ErrMalformedDocID = errors.New("malformed document ID, missing either version or cid")
ErrInvalidDocIDVersion = errors.New("invalid document ID version")
ErrInvalidJSONPayload = errors.New(errInvalidJSONPayload)
ErrPrimarySideNotDefined = errors.New(errPrimarySideNotDefined)
)

// NewErrFieldNotExist returns an error indicating that the given field does not exist.
Expand Down Expand Up @@ -155,3 +157,10 @@ func NewErrCRDTKindMismatch(cType, kind string) error {
func NewErrInvalidJSONPaylaod(payload string) error {
return errors.New(errInvalidJSONPayload, errors.NewKV("Payload", payload))
}

func NewErrPrimarySideNotDefined(relationName string) error {
return errors.New(
errPrimarySideNotDefined,
errors.NewKV("RelationName", relationName),
)
}
2 changes: 1 addition & 1 deletion db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func validateUpdateSchemaFields(
}

if !(proposedField.IsPrimaryRelation || relatedField.IsPrimaryRelation) {
return false, NewErrPrimarySideNotDefined(proposedField.RelationName)
return false, client.NewErrPrimarySideNotDefined(proposedField.RelationName)
}

if proposedField.IsPrimaryRelation && relatedField.IsPrimaryRelation {
Expand Down
8 changes: 0 additions & 8 deletions db/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const (
errRelationalFieldInvalidRelationType string = "invalid RelationType"
errRelationalFieldMissingIDField string = "missing id field for relation object field"
errRelationalFieldMissingRelationName string = "missing relation name"
errPrimarySideNotDefined string = "primary side of relation not defined"
errPrimarySideOnMany string = "cannot set the many side of a relation as primary"
errBothSidesPrimary string = "both sides of a relation cannot be primary"
errRelatedFieldKindMismatch string = "invalid Kind of the related field"
Expand Down Expand Up @@ -273,13 +272,6 @@ func NewErrRelationalFieldMissingRelationName(name string) error {
)
}

func NewErrPrimarySideNotDefined(relationName string) error {
return errors.New(
errPrimarySideNotDefined,
errors.NewKV("RelationName", relationName),
)
}

func NewErrPrimarySideOnMany(name string) error {
return errors.New(
errPrimarySideOnMany,
Expand Down

0 comments on commit bd427f3

Please sign in to comment.