Reject text: IC0503: Canister b4q7m-7iaaa-aaaaa-aaerq-cai trapped explicitly: IDL error: unexpected IDL type when parsing Nat

I spent half the day today trying to figure out what was at the root of my unexpected IDL type when parsing... issue. Deleting .dfx/ and restarting with dfx start --clean didn’t help me.

For me, the problem was a mismatch between a local canister’s Actor’s function’s return type and the type I specified for it when I imported it using its cid as described here:

The actual function from the imported canister returned something other than Text, which is why the error complained about unexpected IDL type when parsing Text. I wish the error pointed me to the import line where the erroneous type was specified, or caused the trap to happen somewhere other than “in the promise”. That one took a while to track down.

I had to import the actor this way, which requires you to specify the interface you expect the Actor to have, because the actor was in a different canister than the one I was importing it into and import myCanister "canister:myCanister" was giving me a canister alias "myCanister" not defined even though it was defined in dfx.json and located in the same project. Seems like you can only import actors this way if they are defined in the same canister as the one they’re being imported into. I understand why mainnet IC canisters need to be imported so explicity but it would be nice if there was an easier way to import local canisters defined in separate canisters (but the same project) by name (not cid) and without needing to specify the expected interface since the .did file is available in the project. If it is possible to import without having to specify the cid or interface type, someone please let me know so I can avoid this problem in the future!