Commit 0ea3b26
committed
fix(runtime): keep a rejecting fire-and-forget verb from killing the script
An async verb the script did not await had its raw promise pushed onto
`pending`, and nothing subscribed to it until the `Promise.allSettled`
drain after the script body finished. If the script crossed a tick
boundary in between (the documented `notify("..."); await ask("...")`
pattern does exactly that), Node saw an unhandled rejection first and
tore the process down, so the drain never ran, the awaited verb was
killed mid-flight, and the user got a raw stack trace instead of the
clean one-line error bin/moshcode.mjs prints.
Queue `Promise.allSettled([result])` instead. It subscribes immediately,
so the rejection is observed from the moment it is queued. The script
still receives the original promise, so an awaited call fails exactly as
before, and the drain keeps swallowing fire-and-forget failures as it
already did.
Regression tests cover both halves: an un-awaited rejecting verb no
longer stops a script that keeps running, and an awaited one still
propagates.1 parent d821ab8 commit 0ea3b26
2 files changed
Lines changed: 32 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
62 | 69 | | |
63 | 70 | | |
64 | 71 | | |
65 | 72 | | |
66 | 73 | | |
67 | | - | |
| 74 | + | |
68 | 75 | | |
69 | 76 | | |
70 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
0 commit comments