(error: unknown)
| 231 | |
| 232 | /** True when an error (or any nested cause) is an EADDRINUSE bind failure. */ |
| 233 | export const isAddrInUse = (error: unknown): boolean => { |
| 234 | for (let cursor: unknown = error; cursor instanceof Error; cursor = cursor.cause) { |
| 235 | if ((cursor as NodeJS.ErrnoException).code === "EADDRINUSE") return true; |
| 236 | // The emulate/vite boot glue wraps the OS error in a plain Error whose |
| 237 | // message carries the code, so match the text too. Vite's --strictPort |
| 238 | // exit never says EADDRINUSE at all — the CLI catches the bind failure |
| 239 | // and dies with "Port N is already in use", which reaches us only as |
| 240 | // BootProcessExitError's log tail — so match that phrasing as well, or |
| 241 | // the claimAndBoot re-claim retry never engages for the most common |
| 242 | // collision (a Linux ephemeral outbound socket grabbing the claimed |
| 243 | // port between probe release and vite's bind). |
| 244 | if (/EADDRINUSE|is already in use/.test(cursor.message)) return true; |
| 245 | } |
| 246 | return false; |
| 247 | }; |
| 248 | |
| 249 | /** |
| 250 | * Claim a port block and boot the services that bind it, retrying on EADDRINUSE. |
no outgoing calls
no test coverage detected