Canister [Canister ID] trapped: unknown

Hello, I am getting this error: Canister [Canister ID] trapped: unknown. Does anyone know what this means?

I am calling a backend function in a backend canister in a React frontend.

I confirmed that the frontend is able to access the declaration by console logging the candid declaration.

The full error:
Error fetching proposals: Error: Call failed:
  Canister: [Canister ID]
  Method: [query name]
  "Status": "rejected"
  "Code": "CanisterError"
  "Message": "IC0502: Canister [Canister ID] trapped: unknown"

I was able to resolve this error by resolving an error in my backend canister (using Azle) that was not detected by the compiler.

I am not sure which error it was specifically but:

  • [Probably what caused this error] I recently updated a type within an interface. I did not update the type passed into an update function that used that interface. For example:
const Data = Record({
    id: text,
   amount: int8
})

createData: update([text, nat32], Data, async (id, amount) => {
})
  • [This probably had no impact] I was passing empty function into another function. I updated the function to return a statement.

FYI @lastmjs

Would you be able to provide more details? I don’t quite understand what the issue was, and I’m trying to understand if this is a problem with Azle itself.

It seems that Azle can still compile even with a type mismatch.

For example, here is type Data:

const Data = Record({
    id: text,
   amount: int8
})

In this function, I am passing in type Data - the function accepts a nat32 for amount but amount is actually an int8:

createData: update([text, nat32], Data, async (id, amount) => {
   return data.insert(id, amount);
})

When I run npx azle [canisterName], I do not receive any errors. However, when I test the function in the Candid UI, I will receive a type error.

Does that help?