# What to do when storage::stable\_restore() function fail?

**URL:** <https://forum.dfinity.org/t/what-to-do-when-storage-stable-restore-function-fail/22987>\
**Category:** Developers\
**Tags:** Discussing\
**Created:** [September 13, 2023, 8:40am UTC](https://forum.dfinity.org/t/what-to-do-when-storage-stable-restore-function-fail/22987 "2023-09-13T08:40:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![q2333gh](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/q2333gh/32/36020_2.png) [@q2333gh](https://forum.dfinity.org/u/q2333gh)\
**Post date:** [September 13, 2023, 8:40am UTC](https://forum.dfinity.org/t/what-to-do-when-storage-stable-restore-function-fail/22987/1 "2023-09-13T08:40:07Z")

</div>

The code:

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

```

The error output:

```bash
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.

---

<div class="post-metadata">

**Author:** ![v1ctor](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/v1ctor/32/9360_2.png) [@v1ctor](https://forum.dfinity.org/u/v1ctor)\
**Post date:** [September 13, 2023, 1:16pm UTC](https://forum.dfinity.org/t/what-to-do-when-storage-stable-restore-function-fail/22987/2 "2023-09-13T13:16:23Z")

</div>

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

> **[dfx canister | Internet Computer](https://internetcomputer.org/docs/current/references/cli-reference/dfx-canister#dfx-canister-uninstall-code)**
>
> Use the dfx canister command with flags and subcommands to manage canister operations and interaction with the

---

<div class="post-metadata">

**Author:** ![q2333gh](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/q2333gh/32/36020_2.png) [@q2333gh](https://forum.dfinity.org/u/q2333gh)\
**Post date:** [September 13, 2023, 2:05pm UTC](https://forum.dfinity.org/t/what-to-do-when-storage-stable-restore-function-fail/22987/3 "2023-09-13T14:05:46Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![cymqqqq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/cymqqqq/32/14515_2.png) [@cymqqqq](https://forum.dfinity.org/u/cymqqqq)\
**Post date:** [December 21, 2023, 2:52pm UTC](https://forum.dfinity.org/t/what-to-do-when-storage-stable-restore-function-fail/22987/4 "2023-12-21T14:52:31Z")

</div>

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