deploy_feedback icon indicating copy to clipboard operation
deploy_feedback copied to clipboard

[KV Feedback]: improve Deno.KvCommitError message

Open ngdangtu-vn opened this issue 2 years ago • 1 comments

🔍

  • [x] Did you search for existing issues?

Type of feedback

General feedback

Description

I have a case where delete() atomic operator returns {ok:true} when deleting non-exist keys. This behavior confused me for half of a day because I thought it would return {ok:false} if key not found.

Steps to reproduce (if applicable)

  • use Deno playground to test DenoKV
  • delete the any non-exist/wrong type key

Expected behavior (if applicable)

Return {ok:false}

Possible solution (if applicable)

I think it would be better if we replace ok property with {status: int}. We can implement the SQLite response code system for case. It can offer a better debugging experience.

Additional context

No response

ngdangtu-vn avatar Sep 15 '23 02:09 ngdangtu-vn

The reason why we don't currently provide a mechanism to get whether a delete() actually operated on an existing key is that a blind delete with a non-discarded result is almost always incorrect, and we would like to guide users to use the atomic() API to do it properly.

Say for example you are deleting a user with login "alice". If you call the delete() API, there's a risk of deleting the wrong user: what if between (some previous operation that lead the app logic to delete the user) and the actual delete() call, the user was deleted and another user was created with the same login?

Can you explain your use case a bit?

losfair avatar Sep 18 '23 08:09 losfair