What to do when storage::stable_restore() function fail?

The code:

#[post_upgrade]
fn post_upgrade() {
...
let (db,): (CanisterDB,) = storage::stable_restore().expect("failed to restore users");
...
}

The error output:

Failed during wasm installation call: The replica returned a  
 replica error: Replica Error: reject code CanisterError, reject  
 message Canister v7g7o-oiaaa-aaaag-qcj3q-cai trapped    
 explicitly: Panicked at 'failed to restore users: "Custom(Fail to  
 decode argument 0 from table0 to record {\n  id : nat64;\n  users : vec record {\n    owner : principal;\n    name : text;\n       
 created_at : nat64;\n    custom_wallet_info_array : vec record {\n        id : text;\n      register_time : nat64;\n      front_end_wallet_info :    
 record {\n        addr : text;\n        name : text;\n        w_type : text;\n      };\n    };\n  };\n}\n\nCaused by:\n    0: input:  
 4449444c056c02dbb70178c8dfc9d10a016d026c04e6f99cce0103b3b0dac30368cbe4fdc70471aaacd9d006786 
 e046c05a3b189e30378f7e8d1fc096891f7a7c10a7180f8cde10a71a1cfefc20e71010018270000000000000700011d 
 59e92a95f9572b7c8288384c98e4043780f88f9fdaf193845540469202004abf6d87001b8417_00011da43b9c46bb29f 
 f1c4d7a33c9835892f86089d27f9278be6a03158d5102007f389c20ea22841700011daba05ea5e7778bd8a3a0ae45d0a02aa0fca47bd60eebc16d66fa0d960200f2501ef571c9831700011dc8edb860845b33a9d22f27132746a8598da337dd49d1f123f0737b6b0209757365725f74657374771f18e94115841700011ddae166e8de859b0a811f35ad1836a36950112fef94b0f2f9258b52b4020061c99e7c5753841700011de22ca564a0c1ce5f7c4fa6feaa279acc0fd1a667f2a3c7c2b006e0b002084a6f686e20446f65bb26ff079388821700011de50fe0d3cfde4fe0a7f13a95cf14919ac0f9b9dd6c48e768f02c0be50209757365725f746573741c76a44556158417000 
 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
and many more zeros.

I have changed the data structure within stable memory.
It works every time used to.
I am thinking about clean all stable memory on that canister.
But I can`t find how to do it.

In this case you have to uninstall the canister code before deploying it:

Yes!
I test this local:
It really worked ! Im so happy
Before I was like an ape in Space Odyssey

//local
dfx deploy backend   -m reinstall
//or ic
dfx deploy backend --network ic  -m reinstall

But if you add additional -m parameters, the data will be lost

1 Like