From d7c8bc9da040652f7b81df3bdba038a5317467aa Mon Sep 17 00:00:00 2001 From: boxmein Date: Sat, 23 Nov 2019 16:50:25 +0200 Subject: [PATCH 1/2] Catch errors when trying to derive CWD in Linux, fixes #1576 When the process it tries to read the working dir from has exited, then "/proc/PID/cwd" is an invalid link and fs.readlink() will reject its promise with an error. This results in the terminal "new tab" and "new pane" buttons stopping working, which is very disruptive :( This commit makes sure that the "new tab" and "new pane" buttons keep working, whatever happens. --- terminus-terminal/src/services/sessions.service.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/terminus-terminal/src/services/sessions.service.ts b/terminus-terminal/src/services/sessions.service.ts index 38af203e..0a3a8257 100644 --- a/terminus-terminal/src/services/sessions.service.ts +++ b/terminus-terminal/src/services/sessions.service.ts @@ -291,7 +291,12 @@ export class Session extends BaseSession { return cwd } if (process.platform === 'linux') { - return fs.readlink(`/proc/${this.truePID}/cwd`) + try { + return await fs.readlink(`/proc/${this.truePID}/cwd`) + } catch (exc) { + console.error(exc) + return null + } } if (process.platform === 'win32') { if (!this.guessedCWD) { From 3a67f1eb41d3427e3a0d65143a9d84a11b5c3718 Mon Sep 17 00:00:00 2001 From: boxmein Date: Sat, 23 Nov 2019 23:18:09 +0200 Subject: [PATCH 2/2] Fix linter errors --- terminus-terminal/src/services/sessions.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terminus-terminal/src/services/sessions.service.ts b/terminus-terminal/src/services/sessions.service.ts index 0a3a8257..33dbcb49 100644 --- a/terminus-terminal/src/services/sessions.service.ts +++ b/terminus-terminal/src/services/sessions.service.ts @@ -294,8 +294,8 @@ export class Session extends BaseSession { try { return await fs.readlink(`/proc/${this.truePID}/cwd`) } catch (exc) { - console.error(exc) - return null + console.error(exc) + return null } } if (process.platform === 'win32') {