Hi. I was using passThroughOnException on some workers. I was attempting to gain some safety for the backing origin application, but I seem to have inadvertently cut of my own access to my logging
code excerpt here:
console.log('worker run'); // This is visible in playground
addEventListener('fetch', async event => {
event.passThroughOnException();
event.respondWith(handleRequest(event)); // console.logs inside never seen
});
I realized this only after much confusion, wondering why I saw no logging via my HTTP logger or console.log. I can’t directly attribute passThroughOnException, but removing the passThroughOnException call did bring back log visibility.
It seems like passThroughOnException completely ends the worker execution. I would like to know whether to expect logging via fetch/http and console.log to run when wrapped inside event.waitUntil.
So, does the worker code continue after an exception when passThroughOnException has been called?
I believe there is a bit of confusion going on here.
Your code excerpt is not entirely accurate. Assuming there is no exception, log()s inside your handleRequest() method should show up - and did show up when I tested i just now.
If there is an unhandled exception before you call log(), that log() call certainly wont be executed anymore, hence not show up either.
If you dont catch the exception, it certainly wont, however the request will be passed to the origin. That method doesnt do anything else than set a flag, which signals the executing environment to simply pass on the request to the origin in case of an unhandled exception, instead of returning an 1101 error to the client.
passThroughOnException does not make your exceptions magically vanish, it simply indicates that the request should be forwarded instead of being outright rejected.
I should have been more specific: when there is an unhandled exception inside handleRequest() I do not get logs. My question is whether the v8 context exits and that worker invocation is cleaned up at that time, and whether the initial request is subsequently proxied to the origin, or whether I should expect to be able to log out that there’s been an exception. The latter would require the workers runtime to do some exception handling that is transparent to the user. I’m wondering if that exists.
If a worker invocation is totally by the time the passthrough happens, I will just take another approach in my worker.
I am not quite sure about your question. When you have an exception, no further code is executed. Whether it is then forwarded depends on how you configured it. But I actually addressed all of that. What is not clear about my response?
Yes, you did. Your initial answer gave me a good sense of how to think about this. Thank you I am still pretty new here but I’m pretty invested in the workers product for what I’m working on.