Skip to content

Commit

Permalink
Ignore bogus screen error
Browse files Browse the repository at this point in the history
Closes #17

Co-Authored-By: Andreas Opferkuch <andreas.opferkuch@gmail.com>
  • Loading branch information
simonepri and s-h-a-d-o-w committed Jun 4, 2022
1 parent cafbb74 commit 4fa79c5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/bin.js
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}
Expand Down
60 changes: 60 additions & 0 deletions test/ps.js
Expand Up @@ -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');
});

0 comments on commit 4fa79c5

Please sign in to comment.