Check for null to avoid UnhandledPromiseRejection in Main.Main.SearchActionDelegate.handleAction

An UnhandledPromiseRejection exception is sometimes thrown by
Main.Main.SearchActionDelegate.handleAction, because in this function it
calls UI.inspectorView.currentPanelDeprecated().searchableView(), but
UI.inspectorView.currentPanelDeprecated() can return null.

Call stack:
ShortcutRegistry.js:handleKey
Action.js:handleAction
Main.js:SearchActionDelegate.handleAction

This CL
- checks if UI.inspectorView.currentPanelDeprecated() is null before calling
.searchableView() on it
- fixes return type of currentPanelDeprecated since
UI.viewManager.materializedWidget can return null
- wrap await call in ShortcutRegistry.js:handleKey with try-catch block to
avoid UnhandledPromiseRejection exceptions

Change-Id: I691129dc22da944df35e2134f01821638864b4d0
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1947172
Commit-Queue: Mandy Chen <[email protected]>
Reviewed-by: Robert Paveza <[email protected]>
diff --git a/front_end/main/MainImpl.js b/front_end/main/MainImpl.js
index 5232b94..ab633c6 100644
--- a/front_end/main/MainImpl.js
+++ b/front_end/main/MainImpl.js
@@ -516,10 +516,15 @@
    * @suppressGlobalPropertiesCheck
    */
   handleAction(context, actionId) {
-    const searchableView = UI.SearchableView.fromElement(document.deepActiveElement()) ||
-        UI.inspectorView.currentPanelDeprecated().searchableView();
+    let searchableView = UI.SearchableView.fromElement(document.deepActiveElement());
     if (!searchableView) {
-      return false;
+      const currentPanel = UI.inspectorView.currentPanelDeprecated();
+      if (currentPanel) {
+        searchableView = currentPanel.searchableView();
+      }
+      if (!searchableView) {
+        return false;
+      }
     }
     switch (actionId) {
       case 'main.search-in-panel.find':
diff --git a/front_end/ui/InspectorView.js b/front_end/ui/InspectorView.js
index c96e2a7..3a4efc5 100644
--- a/front_end/ui/InspectorView.js
+++ b/front_end/ui/InspectorView.js
@@ -190,10 +190,10 @@
   }
 
   /**
-   * @return {!UI.Panel}
+   * @return {?UI.Panel}
    */
   currentPanelDeprecated() {
-    return /** @type {!UI.Panel} */ (UI.viewManager.materializedWidget(this._tabbedPane.selectedTabId || ''));
+    return /** @type {?UI.Panel} */ (UI.viewManager.materializedWidget(this._tabbedPane.selectedTabId || ''));
   }
 
   /**
diff --git a/front_end/ui/ShortcutRegistry.js b/front_end/ui/ShortcutRegistry.js
index 9ebb8af..292f19c 100644
--- a/front_end/ui/ShortcutRegistry.js
+++ b/front_end/ui/ShortcutRegistry.js
@@ -135,8 +135,14 @@
       return;
     }
     for (const action of actions) {
-      if (await action.execute()) {
-        return;
+      try {
+        const result = await action.execute();
+        if (result) {
+          return;
+        }
+      } catch (e) {
+        console.error(e);
+        throw e;
       }
     }