Skip to content

Commit

Permalink
packager: JSONReporter: expose errors correctly
Browse files Browse the repository at this point in the history
Reviewed By: cpojer

Differential Revision: D4536721

fbshipit-source-id: d8969a42e844da809bd167cbc1bae2cb11f1db57
  • Loading branch information
Jean Lauliac authored and facebook-github-bot committed Feb 10, 2017
1 parent 49ef06f commit e56b5be
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packager/src/lib/JsonReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,28 @@

import {Writable} from 'stream';

class JsonReporter<TEvent> {
class JsonReporter<TEvent: {}> {

_stream: Writable;

constructor(stream: Writable) {
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) {
/* $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');
}

Expand Down

0 comments on commit e56b5be

Please sign in to comment.