From eff1ce5ba7e3f2c2efefd9d2a9f53e8f89937fde Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Thu, 11 Feb 2021 05:06:28 -0800 Subject: [PATCH] Catch errors when querying physical devices Summary: This is our #1 error and always means there's something off with the user's setup. Reviewed By: mweststrate Differential Revision: D26370974 fbshipit-source-id: 5e2644ce9de8a7d28614a22fab5ce54dab0561d3 --- desktop/app/src/utils/iOSContainerUtility.tsx | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/desktop/app/src/utils/iOSContainerUtility.tsx b/desktop/app/src/utils/iOSContainerUtility.tsx index c08b56906..88e55bd4c 100644 --- a/desktop/app/src/utils/iOSContainerUtility.tsx +++ b/desktop/app/src/utils/iOSContainerUtility.tsx @@ -64,37 +64,47 @@ async function targets(idbPath: string): Promise> { // But idb is MUCH more CPU efficient than instruments, so // when installed, use it. if (await memoize(isAvailable)(idbPath)) { - return safeExec(`${idbPath} list-targets --json`).then(({stdout}) => - // It is safe to assume this to be non-null as it only turns null - // if the output redirection is misconfigured: - // https://stackoverflow.com/questions/27786228/node-child-process-spawn-stdout-returning-as-null - stdout! - .toString() - .trim() - .split('\n') - .map((line) => line.trim()) - .filter(Boolean) - .map((line) => JSON.parse(line)) - .filter(({type}: IdbTarget) => type !== 'simulator') - .map((target: IdbTarget) => { - return {udid: target.udid, type: 'physical', name: target.name}; - }), - ); + return safeExec(`${idbPath} list-targets --json`) + .then(({stdout}) => + // It is safe to assume this to be non-null as it only turns null + // if the output redirection is misconfigured: + // https://stackoverflow.com/questions/27786228/node-child-process-spawn-stdout-returning-as-null + stdout! + .toString() + .trim() + .split('\n') + .map((line) => line.trim()) + .filter(Boolean) + .map((line) => JSON.parse(line)) + .filter(({type}: IdbTarget) => type !== 'simulator') + .map((target: IdbTarget) => { + return {udid: target.udid, type: 'physical', name: target.name}; + }), + ) + .catch((e: Error) => { + console.warn('Failed to query idb for targets:', e); + return []; + }); } else { await killOrphanedInstrumentsProcesses(); - return safeExec('instruments -s devices').then(({stdout}) => - stdout! - .toString() - .split('\n') - .map((line) => line.trim()) - .filter(Boolean) - .map((line) => /(.+) \([^(]+\) \[(.*)\]( \(Simulator\))?/.exec(line)) - .filter(notNull) - .filter(([_match, _name, _udid, isSim]) => !isSim) - .map(([_match, name, udid]) => { - return {udid: udid, type: 'physical', name: name}; - }), - ); + return safeExec('instruments -s devices') + .then(({stdout}) => + stdout! + .toString() + .split('\n') + .map((line) => line.trim()) + .filter(Boolean) + .map((line) => /(.+) \([^(]+\) \[(.*)\]( \(Simulator\))?/.exec(line)) + .filter(notNull) + .filter(([_match, _name, _udid, isSim]) => !isSim) + .map(([_match, name, udid]) => { + return {udid, type: 'physical', name}; + }), + ) + .catch((e) => { + console.warn('Failed to query instruments:', e); + return []; + }); } }