I’m migrating Juno’s codebase to ic_cdk 0.18.3, and while doing so, a few tests are failing for the following reasons:
2021-05-06 19:17:10.000000213 UTC: [Canister lxzze-o7777-77777-aaaaa-cai] [ic-cdk-timers] canister_global_timer: CallRejected(CallRejected { raw_reject_code: 5, reject_message: “IC0503: Error from Canister lxzze-o7777-77777-aaaaa-cai: Canister called ic0.trap with message: ‘Panicked at ‘Call already trapped’, /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ic-cdk-executor-1.0.0/src/lib.rs:80:13’.\nConsider gracefully handling failures from this canister or altering the canister to handle exceptions. See documentation: https://internetcomputer.org/docs/current/references/execution-errors#trapped-explicitly” })
What breaking changes could have caused this error? Or is there a bug?
I’ve upgraded the dependencies and adapted the usage of ic_cdk::futures::spawn, but aside from that, I haven’t made any other changes.
Could you point me to the failing tests? Also, it might be worthwile to look into spawn ordering changes and custom macros section in the migration guide as they might be related.
I had a look at the spawn ordering. As far I can tell after double checking, I think, I actually never “depend on the code in the spawned future running before the code below”, as mentioned in the CHANGELOG, so I assume it should be fine.
As for custom macros, I don’t even know how they work, so we can safely assume I don’t use them.
git clone https://github.com/junobuild/juno
cd juno
git checkout build/ic-cdk-18
npm ci
mkdir -p target/deploy # side note: I should fix this
# Install required tools:
# see HACKING.md
# https://github.com/junobuild/juno/blob/main/HACKING.md#required-tools
# might also be able to just run the script ./docker/bootstrap
npm run build:test-sputnik
npm run test src/tests/specs/sputnik/sputnik.sdk.get-doc-store.spec.ts
Juno appears to use many custom macros from the crate at path libs/macros, which has not been updated to the new boilerplate described in the migration guide.
2021-05-06 19:17:10.000000213 UTC: [Canister lxzze-o7777-77777-aaaaa-cai] Panicked at ‘in_*_context called within an existing async context’, /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ic-cdk-executor-1.0.0/src/lib.rs:152:13
2021-05-06 19:17:10.000000213 UTC: [Canister lxzze-o7777-77777-aaaaa-cai] [ic-cdk-timers] canister_global_timer: CallRejected(CallRejected { raw_reject_code: 5, reject_message: “IC0503: Error from Canister lxzze-o7777-77777-aaaaa-cai: Canister called ic0.trap with message: ‘Panicked at ‘in_*_context called within an existing async context’, /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ic-cdk-executor-1.0.0/src/lib.rs:152:13’.\nConsider gracefully handling failures from this canister or altering the canister to handle exceptions. See documentation: https://internetcomputer.org/docs/current/references/execution-errors#trapped-explicitly” })
Okay, so I did misinterpret and you’re backending to the CDK macros somewhere. By exported functions, to be clear, I just mean the ones that start with canister_ - non-entrypoints don’t count. So you don’t need to insert any new calls (you would spot those as #[export_name = "canister_update myfunction"]).
Further testing indicates that you are, in fact, running afoul of spawn ordering, though I couldn’t tell you where. If I patch your crate to use this hack, the test passes. We intend this function to ship in the next release.
Awesome, thanks! Migrating all spawn functions to spawn_017_compat resolves two of the three tests that were failing but, there is one that ends in error.
npm run test src/tests/specs/sputnik/sputnik.ic-cdk-call.spec.ts