From 4fa79c596d94998ec666639bbe4623432e6a1349 Mon Sep 17 00:00:00 2001 From: simonepri Date: Sat, 4 Jun 2022 15:58:28 +0200 Subject: [PATCH] Ignore bogus screen error Closes #17 Co-Authored-By: Andreas Opferkuch --- lib/bin.js | 12 +++++++++++ test/ps.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/lib/bin.js b/lib/bin.js index 1e917cc..e82f868 100644 --- a/lib/bin.js +++ b/lib/bin.js @@ -2,6 +2,17 @@ var spawn = require('child_process').spawn; +function stripStderr(stderr) { + if (!stderr) return; + stderr = stderr.trim(); + // Strip bogus screen size error. + // See https://github.com/microsoft/vscode/issues/98590 + var regex = /your \d+x\d+ screen size is bogus\. expect trouble/gi; + stderr = stderr.replace(regex, ''); + + return stderr.trim(); +} + /** * Spawn a binary and read its stdout. * @param {String} cmd The name of the binary to spawn. @@ -38,6 +49,7 @@ function run(cmd, args, options, done) { if (executed) return; executed = true; + stderr = stripStderr(stderr); if (stderr) { return done(new Error(stderr)); } diff --git a/test/ps.js b/test/ps.js index 6cd06e0..c9d14e3 100644 --- a/test/ps.js +++ b/test/ps.js @@ -74,3 +74,63 @@ test('should parse ps output on *nix', async t => { mockery.deregisterMock('child_process'); mockery.deregisterMock('os'); }); + +test('should throw if stderr contains an error', async t => { + const stdout = + 'PPID PID\n' + + ' 1 430\n' + + ' 430 432\n' + + ' 1 727\n' + + ' 1 7166\n'; + + mockery.registerMock('child_process', { + spawn: () => mocks.spawn(stdout, 'Some error', null, 0, null), + }); + mockery.registerMock('os', { + EOL: '\n', + platform: () => 'linux', + type: () => 'type', + release: () => 'release', + }); + + const ps = require('../lib/ps'); + + await t.throws(pify(ps)()); + + mockery.deregisterMock('child_process'); + mockery.deregisterMock('os'); +}); + +test('should not throw if stderr contains the "bogus" error message from vscode', async t => { + const stdout = + 'PPID PID\n' + + ' 1 430\n' + + ' 430 432\n' + + ' 1 727\n' + + ' 1 7166\n'; + + mockery.registerMock('child_process', { + spawn: () => + mocks.spawn( + stdout, + 'your 131072x1 screen size is bogus. expect trouble', + null, + 0, + null + ), + }); + mockery.registerMock('os', { + EOL: '\n', + platform: () => 'linux', + type: () => 'type', + release: () => 'release', + }); + + const ps = require('../lib/ps'); + + const result = await pify(ps)(); + t.deepEqual(result, [[1, 430], [430, 432], [1, 727], [1, 7166]]); + + mockery.deregisterMock('child_process'); + mockery.deregisterMock('os'); +});