Agent-js not a tuple type

Agent-js is throwing an error not a tuple type.

I guess from there:

decodeValue(b, t) {
        const tuple = this.checkType(t);
        if (!(tuple instanceof TupleClass)) {
            throw new Error('not a tuple type');
        }

That’s my code:

export const setManyDocs = async ({
  docs,
  satellite
}: {
  docs: {collection: string; doc: Doc<any>}[];
  satellite: Satellite;
}): Promise<Doc<any>[]> => {
  const {set_many_docs} = await getSatelliteActor(satellite);

  const payload: [string, string, SetDoc][] = [];
  for (const {collection, doc} of docs) {
    const {key} = doc;
    payload.push([collection, key, await toSetDoc(doc)]);
  }

  const updatedDocs = await set_many_docs(payload);

  const results: Doc<any>[] = [];
  for (const {doc: updatedDoc, key} of updatedDocs) {
    results.push(await fromDoc({key, doc: updatedDoc}));
  }

  return results;
};

Nothing particular expect the usage of any of course which I agree is not recommended but, make sense in this particular feature and it happens anyway after the error given that it fails at set_many_docs.

chunk-V4APK5XV.js?v=7438eb6e:4329 Uncaught (in promise) Error: not a tuple type
at t6.decodeValue (chunk-V4APK5XV.js?v=7438eb6e:4329:13)
at t3.decodeValue (chunk-V4APK5XV.js?v=7438eb6e:4158:25)
at chunk-V4APK5XV.js?v=7438eb6e:4789:55
at Array.map ()
at Object.Bs (chunk-V4APK5XV.js?v=7438eb6e:4789:39)
at or2 (@junobuild_core.js?v=99bdc6e4:2480:14)
at i (@junobuild_core.js?v=99bdc6e4:2512:67)
at async ho (@junobuild_core.js?v=99bdc6e4:3217:11)
at async setMany (doc.ts:51:18)
at async document.querySelector.addEventListener.passive (doc.ts:92:45)

So, what’s wrong?

It looks like their might be a discrepency between the IDL used to generate the satellite actor and the response that the satellite canister is returning. The IDL is expecting a tuple somewhere in the response where the canister is not providing one.

2 Likes

Fck me, I’m dumb, of course that’s the IDL/Candid files. I’ve got an unreleased breaking change :man_facepalming:.

I :heart: meaningful error message.

Thanks a tone @NathanosDev, I owe you a drink!

1 Like

Great, glad that helped!

I agree the error message could be improved a lot, I had to read the agent-js code to figure out what it meant.

1 Like