importing `edge-runtime` breaks process exit behavior
If I import the edge runtime, then my process has an uncaught exception, my process exits with no error message and an exit code of 0.
Reproduction: https://github.com/EndangeredMassa/reproduction-process-exit-behavior
Example:
import { EdgeRuntime } from 'edge-runtime';
throw new Error('intentional break');
It seems that these lines are the cause: https://github.com/vercel/edge-runtime/blob/ccdb203e6e7e7c46d16c594dba03288e1e967e3a/packages/runtime/src/edge-runtime.ts#L64-L76
Hey @EndangeredMassa! Thank you for this.
@javivelasco and I did a bit of analysis.
The reason why we caught exceptions & rejections at process level within EdgeRuntime is to avoid exiting the runtime itself. This way, the runtime is resilient to exception/rejections occurring within the executed user code. Instead, it reports them using events, allowing caller code to gracefully handle them
But this creates that undesirable side you demonstrated: the simple import of the EdgeRuntime swallows everything! Very bad.
Our plan is the following:
- make a distinction between errors happening during user code execution, and at process level
- for the first error group, keep the current behavior (no exit, call event handlers instead)
- for the second error group, propagate the error, so it stops and sets exit code
How does it sounds to you?
That sounds good to me, thanks!