From 5337a6052dfb53b18c895dde040649a2f6fa5107 Mon Sep 17 00:00:00 2001 From: Dieter Reinert Date: Mon, 9 Dec 2024 13:19:00 +0100 Subject: [PATCH] Handle ENOENT Errors During REPL Socket Cleanup This PR updates the REPL socket cleanup logic to safely handle ENOENT (no such file or directory) errors when attempting to remove stale socket files. Previously, if a socket file did not exist at cleanup time, the process would crash. Now, ENOENT errors are caught and ignored, ensuring stable cleanup behavior. Any other unexpected filesystem errors will still be logged, allowing for better reliability and easier debugging of file-related issues. --- lib/repl.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/repl.ts b/lib/repl.ts index d76e7b3f8e3d..8e025958af94 100644 --- a/lib/repl.ts +++ b/lib/repl.ts @@ -86,7 +86,15 @@ export const Repl = new class { socket.end(); socket.destroy(); }).on('error', () => { - fs.unlinkSync(pathname); + try { + fs.unlinkSync(pathname); + } catch (err: any) { + // If the file doesn't exist, there's nothing to remove. + // Only log the error if it's something other than 'ENOENT'. + if (err.code !== 'ENOENT') { + console.error(`Failed to remove stale socket at ${pathname}:`, err); + } + } }); } }