From 1b0d01ef381d40e1bd0bbe39c67ab1635a56240a Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 29 Mar 2021 06:59:15 -0700 Subject: [PATCH] Give clear messages on how to connect to physical devices Summary: Give clearer instructions when connection to (physical) device fails, rather than just logging errors. Fixes https://github.com/facebook/flipper/issues/1942 Also removed throwing errors for known problems, as they can be remediated by users. Reviewed By: passy Differential Revision: D27360575 fbshipit-source-id: 311d27178d4d205dff725201c7c60f116f0eb319 --- desktop/app/src/utils/iOSContainerUtility.tsx | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/desktop/app/src/utils/iOSContainerUtility.tsx b/desktop/app/src/utils/iOSContainerUtility.tsx index 87d314862..5223ff3d5 100644 --- a/desktop/app/src/utils/iOSContainerUtility.tsx +++ b/desktop/app/src/utils/iOSContainerUtility.tsx @@ -7,6 +7,7 @@ * @format */ +import React from 'react'; import {Mutex} from 'async-mutex'; import {exec as unsafeExec, Output} from 'promisify-child-process'; import {killOrphanedInstrumentsProcesses} from './processCleanup'; @@ -18,6 +19,8 @@ import {promisify} from 'util'; import child_process from 'child_process'; import fs from 'fs-extra'; import path from 'path'; +import fbConfig from '../fb-stubs/config'; +import {notification, Typography} from 'antd'; const exec = promisify(child_process.exec); // Use debug to get helpful logs when idb fails @@ -220,7 +223,8 @@ async function pull( .then(() => { return; }) - .catch((e) => handleMissingIdb(e, idbPath)), + .catch((e) => handleMissingIdb(e, idbPath)) + .catch((e) => handleMissingPermissions(e)), `${operationPrefix}:pull`, ), ); @@ -242,16 +246,52 @@ function handleMissingIdb(e: Error, idbPath: string): void { e.message && e.message.includes('sudo: no tty present and no askpass program specified') ) { - throw new Error( - `idb doesn't appear to be installed. Run "${idbPath} list-targets" to fix this.`, + console.warn(e); + const message = `idb doesn't appear to be installed. Run "${idbPath} list-targets" to fix this.`; + notification.error({ + message: 'Cannot connect to idb', + duration: null, + description: message, + key: 'idb_connection_failed', + }); + return; + } + throw e; +} + +function handleMissingPermissions(e: Error): void { + if ( + e.message && + e.message.includes('Command failed') && + e.message.includes('file pull') && + e.message.includes('sonar/app.csr') + ) { + console.warn(e); + const message = fbConfig.isFBBuild ? ( + <> + Idb lacks permissions to exchange certificates. Did you install a source + build or a debug build with certificate exchange enabled?{' '} + + How To + + + ) : ( + 'Idb lacks permissions to exchange certificates. Did you install a source build?' ); + notification.error({ + message: 'Cannot connect to iOS application', + duration: null, + description: message, + key: 'idb_certificate_pull_failed', + }); + return; } throw e; } function wrapWithErrorMessage(p: Promise): Promise { return p.catch((e: Error) => { - console.error(e); + console.warn(e); // Give the user instructions. Don't embed the error because it's unique per invocation so won't be deduped. throw new Error( "A problem with idb has ocurred. Please run `sudo rm -rf /tmp/idb*` and `sudo yum install -y fb-idb` to update it, if that doesn't fix it, post in Flipper Support.",