ORIGYN-SA / CanDB

CanDB - CanDB is a flexible, performant, and horizontally scalable non-relational multi-canister data storage framework built for the Internet Computer.
Other
29 stars 8 forks source link

Weird error when deleting: Natural subtraction underflow #28

Open vporton opened 6 months ago

vporton commented 6 months ago

My software does some puts, attribute modification. Then I try to delete an existing key:

$ dfx canister call ajuq4-ruaaa-aaaaa-qaaga-cai delete '(record{sk="i/1"})'
Warning: The version of DFX used (0.14.1) is different than the version being run (0.16.1).
This might happen because your dfx.json specifies an older version, or DFX_VERSION is set in your environment.
We are forwarding the command line to the old version. To disable this warning, set the DFX_WARNING=-version_check environment variable.

Error: Failed update call.
Caused by: Failed update call.
  The Replica returned an error: code 5, message: "Canister ajuq4-ruaaa-aaaaa-qaaga-cai trapped explicitly: Natural subtraction underflow"

This happens with the latest version of beta, if I did not confuse anything.

ByronBecker commented 6 months ago

Here's an example of how CanDB can be used with deletion https://github.com/ByronBecker/hello-candb/tree/deletion-example

deleteUser endpoint -> https://github.com/ByronBecker/hello-candb/blob/5a9339509bd8c39fc11c6b381e8a59ad56222cb1/src/helloservice/HelloService.mo#L66

Frontend allowing you to delete a user that has been inserted https://github.com/ByronBecker/hello-candb/blob/5a9339509bd8c39fc11c6b381e8a59ad56222cb1/frontend/src/App.tsx#L130

vporton commented 6 months ago

The error made repeatable by https://github.com/vporton/bug-candb-delete test repo.

Now I am working on a minimal example.

vporton commented 6 months ago

Oops, it is repeatable by commit c6553fc5e5fc9704058a870e52b47fed556db863 in my repo.

vporton commented 6 months ago

I created a nearly minimal example for CanDB: https://github.com/vporton/bug-candb-delete/tree/candb-minimal

The further work is locating the error in CanDB or more likely in BTree.

ByronBecker commented 5 months ago

Fixed in https://github.com/ORIGYN-SA/CanDB/commit/d76760914f424bec8755bf15ece0fc491c1574ec