Browse Source

Merge pull request #3052 from ian-r-rose/show-dialog-on-launcher-error

Show an error dialog if the launcher throws an error.
Steven Silvester 7 years ago
parent
commit
9c9681f5b0

+ 19 - 0
packages/apputils/src/dialog.ts

@@ -39,6 +39,25 @@ function showDialog<T>(options: Partial<Dialog.IOptions<T>>={}): Promise<Dialog.
   return dialog.launch();
 }
 
+/**
+ * Show an error message dialog.
+ *
+ * @param title - The title of the dialog box.
+ *
+ * @param error - the error to show in the dialog body (either a string
+ *   or an object with a string `message` property).
+ */
+export
+function showErrorMessage(title: string, error: any): Promise<void> {
+  console.error(error);
+  let options = {
+    title: title,
+    body: error.message || String(error),
+    buttons: [Dialog.okButton()],
+    okText: 'DISMISS'
+  };
+  return showDialog(options).then(() => { /* no-op */ });
+}
 
 /**
  * A modal dialog widget.

+ 2 - 2
packages/docmanager-extension/src/index.ts

@@ -6,7 +6,7 @@ import {
 } from '@jupyterlab/application';
 
 import {
-  showDialog, Dialog, ICommandPalette, IMainMenu
+  showDialog, showErrorMessage, Dialog, ICommandPalette, IMainMenu
 } from '@jupyterlab/apputils';
 
 import {
@@ -14,7 +14,7 @@ import {
 } from '@jupyterlab/coreutils';
 
 import {
-  renameDialog, DocumentManager, IDocumentManager, showErrorMessage
+  renameDialog, DocumentManager, IDocumentManager
 } from '@jupyterlab/docmanager';
 
 import {

+ 0 - 17
packages/docmanager/src/dialogs.ts

@@ -112,23 +112,6 @@ function shouldOverwrite(path: string): Promise<boolean> {
 }
 
 
-/**
- * An error message dialog to upon document manager errors.
- */
-export
-function showErrorMessage(title: string, error: Error): Promise<void> {
-  console.error(error);
-  let options = {
-    title: title,
-    body: error.message || `File ${title}`,
-    buttons: [Dialog.okButton()],
-    okText: 'DISMISS'
-  };
-  return showDialog(options).then(() => { /* no-op */ });
-}
-
-
-
 /**
  * A widget used to rename a file.
  */

+ 1 - 5
packages/filebrowser/src/browser.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  Toolbar, ToolbarButton
+  showErrorMessage, Toolbar, ToolbarButton
 } from '@jupyterlab/apputils';
 
 import {
@@ -41,10 +41,6 @@ import {
   Uploader
 } from './upload';
 
-import {
-  showErrorMessage
-} from './utils';
-
 
 /**
  * The class name added to file browsers.

+ 3 - 6
packages/filebrowser/src/crumbs.ts

@@ -22,7 +22,7 @@ import {
 } from '@phosphor/widgets';
 
 import {
-  DOMUtils
+  DOMUtils, showErrorMessage
 } from '@jupyterlab/apputils';
 
 import {
@@ -37,9 +37,6 @@ import {
   FileBrowserModel
 } from './model';
 
-import * as utils
-  from './utils';
-
 
 /**
  * The class name added to material icons
@@ -185,7 +182,7 @@ class BreadCrumbs extends Widget {
       if (node.classList.contains(BREADCRUMB_ITEM_CLASS)) {
         let index = ArrayExt.findFirstIndex(this._crumbs, value => value === node);
         this._model.cd(BREAD_CRUMB_PATHS[index]).catch(error =>
-          utils.showErrorMessage('Open Error', error)
+          showErrorMessage('Open Error', error)
         );
 
         // Stop the event propagation.
@@ -285,7 +282,7 @@ class BreadCrumbs extends Widget {
       promises.push(renameFile(manager, oldPath, newPath));
     }
     Promise.all(promises).catch(err => {
-      utils.showErrorMessage('Move Error', err);
+      showErrorMessage('Move Error', err);
     });
   }
 

+ 7 - 14
packages/filebrowser/src/listing.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  Dialog, DOMUtils, showDialog
+  Dialog, DOMUtils, showDialog, showErrorMessage
 } from '@jupyterlab/apputils';
 
 import {
@@ -49,13 +49,6 @@ import {
   FileBrowserModel
 } from './model';
 
-import * as utils
-  from './utils';
-
-import {
-  showErrorMessage
-} from './utils';
-
 
 /**
  * The class name added to DirListing widget.
@@ -366,7 +359,7 @@ class DirListing extends Widget {
     return Promise.all(promises).then(() => {
       return undefined;
     }).catch(error => {
-      utils.showErrorMessage('Paste Error', error);
+      showErrorMessage('Paste Error', error);
     });
   }
 
@@ -418,7 +411,7 @@ class DirListing extends Widget {
     return Promise.all(promises).then(() => {
       return undefined;
     }).catch(error => {
-      utils.showErrorMessage('Duplicate file', error);
+      showErrorMessage('Duplicate file', error);
     });
   }
 
@@ -452,7 +445,7 @@ class DirListing extends Widget {
     return Promise.all(promises).then(() => {
       return undefined;
     }).catch(error => {
-      utils.showErrorMessage('Shutdown kernel', error);
+      showErrorMessage('Shutdown kernel', error);
     });
   }
 
@@ -1106,7 +1099,7 @@ class DirListing extends Widget {
       promises.push(renameFile(manager, path, newPath));
     }
     Promise.all(promises).catch(error => {
-      utils.showErrorMessage('Move Error', error);
+      showErrorMessage('Move Error', error);
     });
   }
 
@@ -1286,7 +1279,7 @@ class DirListing extends Widget {
     for (let name of names) {
       let newPath = PathExt.join(basePath, name);
       let promise = this._model.manager.deleteFile(newPath).catch(err => {
-        utils.showErrorMessage('Delete Failed', err);
+        showErrorMessage('Delete Failed', err);
       });
       promises.push(promise);
     }
@@ -1324,7 +1317,7 @@ class DirListing extends Widget {
       const promise = renameFile(manager, oldPath, newPath);
       return promise.catch(error => {
         if (error !== 'File not renamed') {
-          utils.showErrorMessage('Rename Error', error);
+          showErrorMessage('Rename Error', error);
         }
         this._inRename = false;
         return original;

+ 2 - 5
packages/filebrowser/src/upload.ts

@@ -2,16 +2,13 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  ToolbarButton
+  ToolbarButton, showErrorMessage
 } from '@jupyterlab/apputils';
 
 import {
   FileBrowserModel
 } from './model';
 
-import * as utils
-  from './utils';
-
 
 /**
  * The class name added to a button content node.
@@ -78,7 +75,7 @@ class Uploader extends ToolbarButton {
     let files = Array.prototype.slice.call(this._input.files) as File[];
     let pending = files.map(file => this.model.upload(file));
     Promise.all(pending).catch(error => {
-      utils.showErrorMessage('Upload Error', error);
+      showErrorMessage('Upload Error', error);
     });
   }
 

+ 0 - 21
packages/filebrowser/src/utils.ts

@@ -1,21 +0,0 @@
-// Copyright (c) Jupyter Development Team.
-// Distributed under the terms of the Modified BSD License.
-
-import {
-  Dialog, showDialog
-} from '@jupyterlab/apputils';
-
-/**
- * An error message dialog to show in the filebrowser widget.
- */
-export
-function showErrorMessage(title: string, error: any): Promise<void> {
-  console.error(error);
-  let options = {
-    title: title,
-    body: error.message || `File ${title}`,
-    buttons: [Dialog.okButton()],
-    okText: 'DISMISS'
-  };
-  return showDialog(options).then(() => { /* no-op */ });
-}

+ 2 - 2
packages/launcher/src/index.tsx

@@ -24,7 +24,7 @@ import {
 import * as vdom from '@phosphor/virtualdom';
 
 import {
-  VDomModel, VDomRenderer
+  showErrorMessage, VDomModel, VDomRenderer
 } from '@jupyterlab/apputils';
 
 import '../style/index.css';
@@ -399,7 +399,7 @@ function Card(kernel: boolean, item: ILauncherItem, launcher: Launcher, launcher
       launcher.dispose();
     }).catch(err => {
       launcher.pending = false;
-      throw err;
+      showErrorMessage('Launcher Error', err);
     });
   };
   // Add a data attribute for the category