Skip to content

Commit 383dfe6

Browse files
Ignore bogus screen error
Closes #17 Co-Authored-By: Andreas Opferkuch <[email protected]>
1 parent a0f2877 commit 383dfe6

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

lib/bin.js

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
var spawn = require('child_process').spawn;
44

5+
function stripStderr(stderr) {
6+
if (!stderr) return;
7+
stderr = stderr.trim();
8+
// Strip bogus screen size error.
9+
// See https://github.com/microsoft/vscode/issues/98590
10+
var regex = /your \d+x\d+ screen size is bogus\. expect trouble/gi;
11+
stderr = stderr.replace(regex, '');
12+
13+
return stderr.trim();
14+
}
15+
516
/**
617
* Spawn a binary and read its stdout.
718
* @param {String} cmd The name of the binary to spawn.
@@ -38,6 +49,7 @@ function run(cmd, args, options, done) {
3849
if (executed) return;
3950
executed = true;
4051

52+
stderr = stripStderr(stderr);
4153
if (stderr) {
4254
return done(new Error(stderr));
4355
}

test/ps.js

+60
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,63 @@ test('should parse ps output on *nix', async t => {
7474
mockery.deregisterMock('child_process');
7575
mockery.deregisterMock('os');
7676
});
77+
78+
test('should throw if stderr contains an error', async t => {
79+
const stdout =
80+
'PPID PID\n' +
81+
' 1 430\n' +
82+
' 430 432\n' +
83+
' 1 727\n' +
84+
' 1 7166\n';
85+
86+
mockery.registerMock('child_process', {
87+
spawn: () => mocks.spawn(stdout, 'Some error', null, 0, null),
88+
});
89+
mockery.registerMock('os', {
90+
EOL: '\n',
91+
platform: () => 'linux',
92+
type: () => 'type',
93+
release: () => 'release',
94+
});
95+
96+
const ps = require('../lib/ps');
97+
98+
await t.throws(pify(ps)());
99+
100+
mockery.deregisterMock('child_process');
101+
mockery.deregisterMock('os');
102+
});
103+
104+
test('should not throw if stderr contains the "bogus screen" error message', async t => {
105+
const stdout =
106+
'PPID PID\n' +
107+
' 1 430\n' +
108+
' 430 432\n' +
109+
' 1 727\n' +
110+
' 1 7166\n';
111+
112+
mockery.registerMock('child_process', {
113+
spawn: () =>
114+
mocks.spawn(
115+
stdout,
116+
'your 131072x1 screen size is bogus. expect trouble',
117+
null,
118+
0,
119+
null
120+
),
121+
});
122+
mockery.registerMock('os', {
123+
EOL: '\n',
124+
platform: () => 'linux',
125+
type: () => 'type',
126+
release: () => 'release',
127+
});
128+
129+
const ps = require('../lib/ps');
130+
131+
const result = await pify(ps)();
132+
t.deepEqual(result, [[1, 430], [430, 432], [1, 727], [1, 7166]]);
133+
134+
mockery.deregisterMock('child_process');
135+
mockery.deregisterMock('os');
136+
});

0 commit comments

Comments
 (0)