diff --git a/src/unixTerminal.test.ts b/src/unixTerminal.test.ts index f13e66d4..cfdf45a7 100644 --- a/src/unixTerminal.test.ts +++ b/src/unixTerminal.test.ts @@ -366,6 +366,25 @@ if (process.platform !== 'win32') { done(); }); }); + it('should throw a descriptive error when spawn-helper is missing', () => { + const { loadNativeModule } = require('./utils'); + const nativeModule = loadNativeModule('pty'); + const spawnHelperPath = path.resolve(__dirname, nativeModule.dir + '/spawn-helper'); + const backupPath = spawnHelperPath + '.bak'; + fs.renameSync(spawnHelperPath, backupPath); + try { + assert.throws( + () => new UnixTerminal('/bin/zsh', []), + (e: Error) => { + assert.ok(e.message.includes('spawn-helper not found'), `Unexpected message: ${e.message}`); + assert.ok(e.message.includes(spawnHelperPath), `Path missing from message: ${e.message}`); + return true; + } + ); + } finally { + fs.renameSync(backupPath, spawnHelperPath); + } + }); it('should not leak /dev/ptmx file descriptors after pty exit', async function(): Promise { this.timeout(30000); diff --git a/src/unixTerminal.ts b/src/unixTerminal.ts index 2776d501..61088fd3 100644 --- a/src/unixTerminal.ts +++ b/src/unixTerminal.ts @@ -103,6 +103,9 @@ export class UnixTerminal extends Terminal { }; // fork + if (!fs.existsSync(helperPath)) { + throw new Error(`node-pty spawn-helper not found at '${helperPath}'. This can happen if the application binary has moved since the process started.`); + } const term = pty.fork(file, args, parsedEnv, cwd, this._cols, this._rows, uid, gid, (encoding === 'utf8'), helperPath, onexit); this._socket = new tty.ReadStream(term.fd);