Skip to content

Commit 8d3ce41

Browse files
committed
fix: stderr being emitted in binary mode
1 parent f90f5e5 commit 8d3ce41

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ function getRandomInt(){
3737
}
3838

3939
export interface Options extends SpawnOptions{
40+
/**
41+
* if binary is enabled message and stderr events will not be emitted
42+
*/
4043
mode?: 'text'|'json'|'binary'
4144
formatter?: (param:string)=>any
4245
parser?: (param:string)=>any
@@ -147,7 +150,7 @@ export class PythonShell extends EventEmitter{
147150
}
148151

149152
// listen to stderr and emit errors for incoming data
150-
if (this.stderr) {
153+
if (this.stderrParser && this.stderr) {
151154
this.stderr.on('data', function (data) {
152155
errorData += ''+data;
153156
self.receiveStderr(data);

test/test-python-shell.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ describe('PythonShell', function () {
348348
mode: 'binary'
349349
});
350350
pyshell.receive = function () {
351-
throw new Error('should not emit messages in binary mode');
351+
done('should not emit messages in binary mode');
352+
return undefined
352353
};
353354
pyshell.end(done);
354355
});
@@ -385,12 +386,12 @@ describe('PythonShell', function () {
385386
}).send('hello').send('world').end(done);
386387
});
387388
it('should not be invoked when mode is "binary"', function (done) {
388-
let pyshell = new PythonShell('echo_args.py', {
389-
args: ['hello', 'world'],
389+
let pyshell = new PythonShell('stderrLogging.py', {
390390
mode: 'binary'
391391
});
392392
pyshell.receiveStderr = function () {
393-
throw new Error('should not emit stderr in binary mode');
393+
done('should not emit stderr in binary mode');
394+
return undefined
394395
};
395396
pyshell.end(done);
396397
});

0 commit comments

Comments
 (0)