Checking for ErrSubDocPathNotFound errors


#1

With this code:

_, mutateErr := bucket.Bucket.MutateInEx(k, gocb.SubdocDocFlagNone, gocb.Cas(0), uint32(0)).
	RemoveEx(xattrKey, gocb.SubdocFlagXattr). // Remove the xattr
	RemoveEx("", gocb.SubdocFlagNone).        // Delete the document body
	Execute()

I’m getting an error subdocument mutation 0 failed (sub-document path does not exist). I’m having trouble doing a comparison against the error however, to try to determine the error type. Eg:

if mutateErr == gocb.ErrSubDocPathNotFound {
    ...
} else {
   .. another kind of error <-- ends up here
}

Isn’t matching as expected. When I dug into it a bit more, it looks like it’s a gocb.ErrSubDocPathNotFound error wrapped inside of a gocbcore.SubDocMutateError.

mutateErr: %!p(gocbcore.SubDocMutateError={0x17931da 0})  gocb.ErrSubDocPathNotFound: 0x17931da

What’s the best way to check whether errors are gocb.ErrSubDocPathNotFound errors?

I’m using gocb commit: https://github.com/couchbase/gocb/commit/0cd63ba8b594091ea0005ec50ee21299e0b22d97


#2

Hey Traun,

There is unfortunately not currently a way to access the underlying cause for subdocument mutation failures (the structure is only exposed via gocbcore, but not gocb). We are currently working on a v2 of gocb with the primary intention on cleaning up our error handling, particularly as the server will soon support contextual information for errors (making direct comparisons no longer a feasible solution anyways). As part of this effort, we will definitely be keeping subdocument context wrapping in mind to ensure easy access to the underlying error.

Cheers, Brett