Get a stack trace on trap

I have a canister that serves generated text via the http_request method. When I try to get a response, I get the following:

Replica Error (5): "IC0503: Canister rrkah-fqaaa-aaaaa-aaaaq-cai trapped explicitly: Array index out of bounds"

Nothing prints out in the console where I started dfx, nor in the developer tools console (except for a 500 (Internal Server Error with no other information).

But I have no idea where in my code the offending array is. How can I find out? It seems that when a canister traps, no stack trace is printed anywhere. I’ve debugged traps before by peppering my motoko code with Debug.print(β€œ1”) and Debug.print(β€œ2”), etc, but surely this can’t be the recommended method of getting to the bottom of an error like this.

Any suggestions?

1 Like