catch errors in logs listener

Summary: If one logListener was to throw an error, the others wouldn't receive the logs anymore.

Reviewed By: jknoxville

Differential Revision: D13881128

fbshipit-source-id: a653ba9279380c25bbc7ae2fd0c63de0884aa441
This commit is contained in:
Daniel Büchele
2019-01-30 10:15:05 -08:00
committed by Facebook Github Bot
parent f12226ac00
commit 599b069943

View File

@@ -98,7 +98,14 @@ export default class BaseDevice {
notifyLogListeners(entry: DeviceLogEntry) {
this.logEntries.push(entry);
if (this.logListeners.size > 0) {
this.logListeners.forEach(listener => listener(entry));
this.logListeners.forEach(listener => {
// prevent breaking other listeners, if one listener doesn't work.
try {
listener(entry);
} catch (e) {
console.error(`Log listener exception:`, e);
}
});
}
}