And the following works fine for deploying the backend wasm to a canister:
await ic.install_code({
arg = []; // Empty arg array for initialization
wasm_module = wasm;
mode = switch (status.module_hash) {
case null #install;
case (?_) #upgrade;
};
canister_id = canisterId;
});
But fails for the front end wasm with:
Error deploying WASM to existing canister: Error from Canister c2lt4-zmaaa-aaaaa-qaaiq-cai: Canister called ic0.trap with message: failed to decode call arguments: Custom(Cannot parse header
Caused by:
binary parser error: io error)
Canister Backtrace:
unknown function at index 1648
unknown function at index 86
unknown function at index 62
unknown function at index 824
.
Consider gracefully handling failures from this canister or altering the canister to handle exceptions. See documentation: Execution errors | Internet Computer
I’ve tried various methods of decompression and then processing as a wasm instead of wasm.gz but I need a little guidance on what the install_code method may be missing in terms of the front end.
I also see that there is a separate “assetstorage.wasm.gz”… thanks in advance for your assistance !
After attempting some suggestions from around the forum, still bumping into the error, but Iv’e tried to align the front end call to install_code based on what appeared to work elsewhere
try {
let status = await ic.canister_status({ canister_id = canisterId });
// Different initialization for different stages
let init_args = switch (canisterType, deploymentStage) {
// Initial assetstorage deployment
case ("frontend", "assetstorage") {
Blob.toArray(to_candid({
stable_memory_size = 0 : Nat32;
max_pages = 0 : Nat16;
}))
};
// Frontend code deployment
case ("frontend", "frontend") {
Blob.toArray(to_candid({
init_args = [] : [Nat8];
upgrade_args = [] : [Nat8];
}))
};
// Backend deployment
case _ {
[] : [Nat8]
};
};
await ic.install_code({
arg = init_args;
wasm_module = wasm;
mode = switch (status.module_hash) {
case null #install;
case (?_) #upgrade;
};
canister_id = canisterId;
});
The to_candid() function is built into the Motoko language, so you can call it without needing to import it from anyway.
Edit:
It looks like you’re converting the candid encoding to an array. That may be what’s causing the issue. Try getting rid of the Blob.toArray function that you’re calling after converting the args to candid.
Lastly, be sure that the structure of the object that you encode as your arg argument conforms to the same structure as whatever input you use when instantiating your canister.
Here’s an example of how I install the wasm for a canister that was instantiated with a single input argument of type Principal
I notice that my method arguments are completely different, this is helpful in terms of just knowing a valid function call, I will try this out, thanks Jesse
I wonder if this works for an upgrade but not a fresh install ?
I tried
let init_args = Blob.toArray(to_candid(canisterId));
await ic.install_code({
arg = init_args;
wasm_module = wasm;
mode = switch (status.module_hash) {
case null #install;
case (?_) #upgrade;
};
canister_id = canisterId;
});
No luck…
2024-12-22 16:02:40.416974 UTC: [Canister bkyz2-fmaaa-aaaaa-qaaaq-cai] Error deploying frontend WASM to existing canister: Error from Canister c2lt4-zmaaa-aaaaa-qaaiq-cai: Canister called ic0.trap with message: Panicked at ‘failed to restore stable state: “Custom(Cannot parse header\n\nCaused by:\n binary parser error: Unexpected bytes at byte offset 0)”’, src/canisters/frontend/ic-frontend-canister/src/lib.rs:18:43
Canister Backtrace:
unknown function at index 1648
unknown function at index 465
unknown function at index 944
unknown function at index 1819
unknown function at index 1262
unknown function at index 1315
unknown function at index 1020
unknown function at index 62
unknown function at index 824
.
Consider gracefully handling failures from this canister or altering the canister to handle exceptions. See documentation: Execution errors | Internet Computer