Skip to content

gracefully handle process.stdin exceptions #2837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/reporters/base-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as languages from './lang/index.js';
import isCI from 'is-ci';

const util = require('util');
const EventEmitter = require('events').EventEmitter;

type Language = $Keys<typeof languages>;

Expand Down Expand Up @@ -55,7 +56,7 @@ export default class BaseReporter {

this.stdout = opts.stdout || process.stdout;
this.stderr = opts.stderr || process.stderr;
this.stdin = opts.stdin || process.stdin;
this.stdin = opts.stdin || this._getStandardInput();
this.emoji = !!opts.emoji;
this.noProgress = !!opts.noProgress || isCI;
this.isVerbose = !!opts.verbose;
Expand Down Expand Up @@ -113,6 +114,21 @@ export default class BaseReporter {
_verbose(msg: string) {}
_verboseInspect(val: any) {}

_getStandardInput(): Stdin {
let standardInput;

try {
standardInput = process.stdin;
} catch (e) {
delete process.stdin;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should console.warn(e.message)?

// $FlowFixMe: this is valid!
process.stdin = new EventEmitter();
standardInput = process.stdin;
}

return standardInput;
}

initPeakMemoryCounter() {
this.checkPeakMemory();
this.peakMemoryInterval = setInterval(() => {
Expand Down