Skip to content

Commit aedebc1

Browse files
authored
Don't override errored state on close event (#461)
1 parent a2e5b19 commit aedebc1

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/command.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ describe('#start()', () => {
151151
expect(command.state).toBe('exited');
152152
});
153153

154+
it('does not change state if there was an error', () => {
155+
const { command } = createCommand();
156+
command.start();
157+
process.emit('error', 'foo');
158+
process.emit('close', 0, null);
159+
expect(command.state).toBe('errored');
160+
});
161+
154162
it('shares start and close timing events to the timing stream', async () => {
155163
const { command, values } = createCommand();
156164
const startDate = new Date();

src/command.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ export class Command implements CommandInfo {
169169
.pipe(Rx.map((event) => event as [number | null, NodeJS.Signals | null]))
170170
.subscribe(([exitCode, signal]) => {
171171
this.process = undefined;
172-
this.state = 'exited';
172+
173+
// Don't override error event
174+
if (this.state !== 'errored') {
175+
this.state = 'exited';
176+
}
173177

174178
const endDate = new Date(Date.now());
175179
this.timer.next({ startDate, endDate });

0 commit comments

Comments
 (0)