Skip to content

Commit 7c7021c

Browse files
committed
fix(shell): handle stdout/stderr stream error
Without this, the 'error' event is unhandled, which results in the process dying. Print the error and move on. Added because of 'write after end' stream error from shelling out Angular CLI. Possibly revert pending this issue: angular/angular-cli#10922
1 parent 6109723 commit 7c7021c

File tree

1 file changed

+19
-3
lines changed
  • packages/@ionic/cli-utils/src/lib

1 file changed

+19
-3
lines changed

packages/@ionic/cli-utils/src/lib/shell.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from 'path';
22
import { ChildProcess } from 'child_process';
33

44
import chalk from 'chalk';
5-
5+
import * as Debug from 'debug';
66
import * as split2 from 'split2';
77

88
import { ERROR_SHELL_COMMAND_NOT_FOUND, LOGGER_LEVELS, ShellCommandError } from '@ionic/cli-framework';
@@ -14,6 +14,8 @@ import { ILogger, IShell, IShellOutputOptions, IShellRunOptions, IShellSpawnOpti
1414
import { isExitCodeException } from '../guards';
1515
import { FatalException } from './errors';
1616

17+
const debug = Debug('ionic:cli-utils:lib:shell');
18+
1719
export interface ShellDeps {
1820
log: ILogger;
1921
projectDir?: string;
@@ -45,11 +47,25 @@ export class Shell implements IShell {
4547
const promise = cmd.run();
4648

4749
if (promise.p.stdout) {
48-
promise.p.stdout.pipe(combineStreams(split2(), ws));
50+
const stream = combineStreams(split2(), ws);
51+
52+
// TODO: https://github.com/angular/angular-cli/issues/10922
53+
stream.on('error', (err: Error) => {
54+
debug('Error in subprocess stdout pipe: %o', err);
55+
});
56+
57+
promise.p.stdout.pipe(stream);
4958
}
5059

5160
if (promise.p.stderr) {
52-
promise.p.stderr.pipe(combineStreams(split2(), ws));
61+
const stream = combineStreams(split2(), ws);
62+
63+
// TODO: https://github.com/angular/angular-cli/issues/10922
64+
stream.on('error', (err: Error) => {
65+
debug('Error in subprocess stderr pipe: %o', err);
66+
});
67+
68+
promise.p.stderr.pipe(stream);
5369
}
5470

5571
if (killOnExit) {

0 commit comments

Comments
 (0)