how to debug a function

I'm creating a webhook in Supabase to update a CF Worker KV. The point is that for every post request I can get the payload data but I cannot get any more info apart that post request is cancelled
"outcome": "canceled"
"outcome": "canceled"
I mean, I create conselo.log but this info doesn't show up in the request Real-time Logs. How can I get debug info in the log?
14 Replies
JustinNoel
JustinNoel2y ago
I'd try to wrap your whole handler in a try/catch. Then, in the catch, console log whatever errr you may be getting.
rodrigo
rodrigoOP2y ago
I have several try/catch but I don't get any error. I've set some console.log and I have some info that look ok ... But the point is requests are cancelled and the only info is "outcome": "canceled",. No idea how to get more info.... I've also set up the the Wokers to Unbound .
JustinNoel
JustinNoel2y ago
Where do you see this? What's it from?
"outcome": "canceled"
rodrigo
rodrigoOP2y ago
In the Real-time Logs. It's clear it's due to an error in my code, but I cannot find a way to get more debug info than this 'canceled' (and I've set up try/catch everywhere in my code
rodrigo
rodrigoOP2y ago
JustinNoel
JustinNoel2y ago
I use some middleware to collect logs and send them to an external service when a request completes. It took me a while to get that working well. A "simple" troublshooting technique you can use is to litter some KV writes throughout your code. If it gets to KV write #1, #2, and #3, you know that code is good. But if KV write #4 doesn't exist, you know the problem is between 3 and 4.
GregBrimble
GregBrimble2y ago
"canceled" usually means the client went away, IIRC
rodrigo
rodrigoOP2y ago
The client is a Supabase webhook that reaches a Remix action. Might the "cancelled" be due to the webhook goes away to soon? Could I use a header in the webhook to avoid this?
GregBrimble
GregBrimble2y ago
If you hit the Remix action directly with curl or whatever, what happens?
rodrigo
rodrigoOP2y ago
I've replicated the webhook post request in Postman with the same payload and it works! But it lasts 1300ms ... the webhook might be dropping the connection because it lasts too much? (it a Supabase webhook, working on AWS (Lambdas???) )
GregBrimble
GregBrimble2y ago
Perhaps. I’m not super familiar with how Supabase webhooks work. Might be worth moving the work into waitUntil() (or even using Queues if it’s going to get any more chunky) so you can return a response faster?
rodrigo
rodrigoOP2y ago
You mean to place all functions within a context.waitUntil() in the Remix action?
GregBrimble
GregBrimble2y ago
Just the bulk of the work that you’re doing, yeah
rodrigo
rodrigoOP2y ago
I think it works with waitUntil. I need to test it it deeper, but it seems to work! Thanks!
Want results from more Discord servers?
Add your server