A TypeScript client does not work for DFINITY Motoko:
function initializeDirectCanDBPartitionClient(canisterId: Principal)
{
const host = isLocal ? "http://127.0.0.1:8000" : "https://ic0.app";
const agent = new HttpAgent({ host });
return Actor.createActor(CanDBPartitionIDL, { agent, canisterId });
};
...
const client = initializeDirectCanDBPartitionClient(obj.itemRef.canister);
obj.item = await client.getItem(BigInt(obj.itemRef.id)) as any;
produces
Uncaught (in promise) Error: Call failed:
Canister: a3shf-5eaaa-aaaaa-qaafa-cai
Method: getItem (query)
"Status": "rejected"
"Code": "CanisterError"
"Message": "IC0503: Canister a3shf-5eaaa-aaaaa-qaafa-cai trapped explicitly: Array index out of bounds"
at caller (index.js:184:27)
at async ItemData.create (index.js:78705:20)
But
public query func getItem(itemId: Nat): async ?lib.Item {
Debug.print("ITEMXXX");
return null; // to ensure the action is completely done
let data = _getAttribute({sk = "i/" # Nat.toText(itemId)}, "i");
Debug.print("ITEM: " # debug_show(data));
do ? { lib.deserializeItem(data!) };
};
should output at least ITEMXXX
, which however does not appear in the logs of dfx start
.
Why the error?!