packager: JSONReporter: expose errors correctly

Reviewed By: cpojer

Differential Revision: D4536721

fbshipit-source-id: d8969a42e844da809bd167cbc1bae2cb11f1db57
This commit is contained in:
Jean Lauliac 2017-02-10 09:25:53 -08:00 committed by Facebook Github Bot
parent 7b301aa3a4
commit 96a7d25bdf
1 changed files with 14 additions and 1 deletions

View File

@ -13,7 +13,7 @@
import {Writable} from 'stream'; import {Writable} from 'stream';
class JsonReporter<TEvent> { class JsonReporter<TEvent: {}> {
_stream: Writable; _stream: Writable;
@ -21,7 +21,20 @@ class JsonReporter<TEvent> {
this._stream = stream; this._stream = stream;
} }
/**
* There is a special case for errors because they have non-enumerable fields.
* (Perhaps we should switch in favor of plain object?)
*/
update(event: TEvent) { update(event: TEvent) {
/* $FlowFixMe: fine to call on `undefined`. */
if (Object.prototype.toString.call(event.error) === '[object Error]') {
event = {...event};
event.error = {
...event.error,
message: event.error.message,
stack: event.error.stack,
};
}
this._stream.write(JSON.stringify(event) + '\n'); this._stream.write(JSON.stringify(event) + '\n');
} }