From 238374f4db67ae747899f8434bffe69daa4dae21 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Wed, 31 Mar 2021 01:38:58 -0700 Subject: [PATCH] Fix uncaught exception in adb logging Summary: Found some random unhandled rejection. Added error catching / logging to adb logcat setup. {F558587842} Reviewed By: passy Differential Revision: D27429914 fbshipit-source-id: faca682819a2f1a3f924ee176cc9f8c9f92f5ae9 --- desktop/app/src/devices/AndroidDevice.tsx | 71 +++++++++++++---------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/desktop/app/src/devices/AndroidDevice.tsx b/desktop/app/src/devices/AndroidDevice.tsx index 4b32b0450..2f22ee426 100644 --- a/desktop/app/src/devices/AndroidDevice.tsx +++ b/desktop/app/src/devices/AndroidDevice.tsx @@ -44,39 +44,48 @@ export default class AndroidDevice extends BaseDevice { } startLogging() { - this.adb.openLogcat(this.serial, {clear: true}).then((reader) => { - this.reader = reader; - reader.on('entry', (entry) => { - let type: LogLevel = 'unknown'; - if (entry.priority === Priority.VERBOSE) { - type = 'verbose'; - } - if (entry.priority === Priority.DEBUG) { - type = 'debug'; - } - if (entry.priority === Priority.INFO) { - type = 'info'; - } - if (entry.priority === Priority.WARN) { - type = 'warn'; - } - if (entry.priority === Priority.ERROR) { - type = 'error'; - } - if (entry.priority === Priority.FATAL) { - type = 'fatal'; - } + this.adb + .openLogcat(this.serial, {clear: true}) + .then((reader) => { + this.reader = reader; + reader + .on('entry', (entry) => { + let type: LogLevel = 'unknown'; + if (entry.priority === Priority.VERBOSE) { + type = 'verbose'; + } + if (entry.priority === Priority.DEBUG) { + type = 'debug'; + } + if (entry.priority === Priority.INFO) { + type = 'info'; + } + if (entry.priority === Priority.WARN) { + type = 'warn'; + } + if (entry.priority === Priority.ERROR) { + type = 'error'; + } + if (entry.priority === Priority.FATAL) { + type = 'fatal'; + } - this.addLogEntry({ - tag: entry.tag, - pid: entry.pid, - tid: entry.tid, - message: entry.message, - date: entry.date, - type, - }); + this.addLogEntry({ + tag: entry.tag, + pid: entry.pid, + tid: entry.tid, + message: entry.message, + date: entry.date, + type, + }); + }) + .on('error', (e) => { + console.warn('Failed to read from adb logcat: ', e); + }); + }) + .catch((e) => { + console.warn('Failed to open log stream: ', e); }); - }); } stopLogging() {