diff --git a/db/collection.go b/db/collection.go index a9131037c9..5810a4745b 100644 --- a/db/collection.go +++ b/db/collection.go @@ -653,10 +653,10 @@ func (c *collection) create(ctx context.Context, txn datastore.Txn, doc *client. return err } if exists { - return ErrDocumentAlreadyExists + return NewErrDocumentAlreadyExists(primaryKey.DocKey) } if isDeleted { - return ErrDocumentDeleted + return NewErrDocumentDeleted(primaryKey.DocKey) } // write value object marker if we have an empty doc @@ -696,7 +696,7 @@ func (c *collection) Update(ctx context.Context, doc *client.Document) error { return client.ErrDocumentNotFound } if isDeleted { - return ErrDocumentDeleted + return NewErrDocumentDeleted(primaryKey.DocKey) } err = c.update(ctx, txn, doc) @@ -886,7 +886,7 @@ func (c *collection) Delete(ctx context.Context, key client.DocKey) (bool, error return false, client.ErrDocumentNotFound } if isDeleted { - return false, ErrDocumentDeleted + return false, NewErrDocumentDeleted(primaryKey.DocKey) } err = c.applyDelete(ctx, txn, primaryKey) diff --git a/db/collection_delete.go b/db/collection_delete.go index acbdb26404..480656849f 100644 --- a/db/collection_delete.go +++ b/db/collection_delete.go @@ -239,7 +239,7 @@ func (c *collection) applyDelete( return client.ErrDocumentNotFound } if isDeleted { - return ErrDocumentDeleted + return NewErrDocumentDeleted(key.DocKey) } dsKey := key.ToDataStoreKey() diff --git a/db/errors.go b/db/errors.go index 7aa1cc5656..7642ca7253 100644 --- a/db/errors.go +++ b/db/errors.go @@ -35,6 +35,8 @@ const ( errInvalidCRDTType string = "only default or LWW (last writer wins) CRDT types are supported" errCannotDeleteField string = "deleting an existing field is not supported" errFieldKindNotFound string = "no type found for given name" + errDocumentAlreadyExists string = "a document with the given dockey already exists" + errDocumentDeleted string = "a document with the given dockey has been deleted" ) var ( @@ -57,8 +59,8 @@ var ( ErrMergeSubTypeNotSupported = errors.New("merge doesn't support sub types yet") ErrInvalidFilter = errors.New("invalid filter") ErrInvalidOpPath = errors.New("invalid patch op path") - ErrDocumentAlreadyExists = errors.New("a document with the given dockey already exists") - ErrDocumentDeleted = errors.New("a document with the given dockey has been deleted") + ErrDocumentAlreadyExists = errors.New(errDocumentAlreadyExists) + ErrDocumentDeleted = errors.New(errDocumentDeleted) ErrUnknownCRDTArgument = errors.New("invalid CRDT arguments") ErrUnknownCRDT = errors.New("unknown crdt") ErrSchemaFirstFieldDocKey = errors.New("collection schema first field must be a DocKey") @@ -214,3 +216,17 @@ func NewErrCannotDeleteField(name string, id client.FieldID) error { errors.NewKV("ID", id), ) } + +func NewErrDocumentAlreadyExists(dockey string) error { + return errors.New( + errDocumentAlreadyExists, + errors.NewKV("DocKey", dockey), + ) +} + +func NewErrDocumentDeleted(dockey string) error { + return errors.New( + errDocumentDeleted, + errors.NewKV("DocKey", dockey), + ) +} diff --git a/tests/integration/mutation/simple/create/simple_test.go b/tests/integration/mutation/simple/create/simple_test.go index cc650f910b..3c590f4098 100644 --- a/tests/integration/mutation/simple/create/simple_test.go +++ b/tests/integration/mutation/simple/create/simple_test.go @@ -93,7 +93,7 @@ func TestMutationCreateSimpleDoesNotCreateDocGivenDuplicate(t *testing.T) { }`, }, }, - ExpectedError: "a document with the given dockey already exists", + ExpectedError: "a document with the given dockey already exists. DocKey: ", } simpleTests.ExecuteTestCase(t, test)