Skip to content

Commit 0e0d21e

Browse files
Handle errors when deleting dev-mode PID file on exit
The `onExited` listener in `writePidIfInDevMode` is `async`, but VS Code `Event` listeners are fire-and-forget: the returned promise is never awaited. As Copilot noted on #5515, that means a rejection from `fs.delete(...)` would surface as an unhandled promise rejection, and the debug log would be skipped on failure. I kept the `async`/`await` form for readability and wrapped the body in `try`/`catch` so nothing escapes: a fully-caught async body resolves normally, and any failure is now logged via `this.logger.writeError` instead of going unhandled. The original `main` version floated the delete promise and logged success unconditionally, swallowing errors. Drafted by Copilot (Claude Opus 4.8). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 21fae13 commit 0e0d21e

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎src/session.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,14 @@ export class SessionManager implements Middleware {
387387
await fs.writeFile(pidFilePath, Buffer.from(pid));
388388
const deletePidOnExit = pwshProcess.onExited(async () => {
389389
deletePidOnExit.dispose();
390-
await fs.delete(pidFilePath, { useTrash: false });
391-
this.logger.writeDebug(`Deleted PID file: ${pidFilePath}`);
390+
try {
391+
await fs.delete(pidFilePath, { useTrash: false });
392+
this.logger.writeDebug(`Deleted PID file: ${pidFilePath}`);
393+
} catch (err) {
394+
this.logger.writeError(
395+
`Error occurred while deleting PID file:\n${err}`,
396+
);
397+
}
392398
});
393399
this.registeredCommands.push(deletePidOnExit);
394400
this.extensionContext.subscriptions.push(deletePidOnExit);

0 commit comments

Comments
 (0)