Browse Source

Merge pull request #1271 from blink1073/server-connection-collapse

Avoid cascading file server errors
Afshin Darian 8 years ago
parent
commit
1a3548c051
2 changed files with 24 additions and 8 deletions
  1. 16 3
      src/filebrowser/browser.ts
  2. 8 5
      src/filebrowser/model.ts

+ 16 - 3
src/filebrowser/browser.ts

@@ -89,6 +89,7 @@ class FileBrowser extends Widget {
     let model = this._model = options.model;
     let renderer = options.renderer;
 
+    model.connectionFailure.connect(this._onConnectionFailure, this);
     this._crumbs = new BreadCrumbs({ model });
     this._buttons = new FileButtons({
       commands, keymap, manager, model
@@ -155,9 +156,7 @@ class FileBrowser extends Widget {
       if (item.type === 'directory') {
         if (!foundDir) {
           foundDir = true;
-          this._model.cd(item.name).catch(error =>
-            showErrorMessage('Open directory', error)
-          );
+          this._model.cd(item.name);
         }
       } else {
         this.openPath(item.path);
@@ -294,6 +293,19 @@ class FileBrowser extends Widget {
     return this._listing.pathForClick(event);
   }
 
+  /**
+   * Handle a connection lost signal from the model.
+   */
+  private _onConnectionFailure(sender: FileBrowserModel, args: Error): void {
+    if (this._showingError) {
+      return;
+    }
+    this._showingError = true;
+    showErrorMessage('Server Connection Error', args).then(() => {
+      this._showingError = false;
+    });
+  }
+
   private _buttons: FileButtons = null;
   private _commands: CommandRegistry = null;
   private _crumbs: BreadCrumbs = null;
@@ -301,6 +313,7 @@ class FileBrowser extends Widget {
   private _listing: DirListing = null;
   private _manager: DocumentManager = null;
   private _model: FileBrowserModel = null;
+  private _showingError = false;
 }
 
 

+ 8 - 5
src/filebrowser/model.ts

@@ -29,10 +29,6 @@ import {
   IPathTracker
 } from './tracker';
 
-import {
-  showErrorMessage
-} from './utils';
-
 
 /**
  * The duration of auto-refresh in ms.
@@ -88,6 +84,11 @@ class FileBrowserModel implements IDisposable, IPathTracker {
    */
   fileChanged: ISignal<this, Contents.IChangedArgs>;
 
+  /**
+   * A signal emitted when the file browser model loses connection.
+   */
+  connectionFailure: ISignal<this, Error>;
+
   /**
    * Get the current path.
    */
@@ -181,8 +182,8 @@ class FileBrowserModel implements IDisposable, IPathTracker {
       this._onRunningChanged(manager.sessions, manager.sessions.running());
       this.refreshed.emit(void 0);
     }).catch(error => {
-      showErrorMessage('Server Connection Error', error);
       this._pendingPath = null;
+      this.connectionFailure.emit(error);
     });
     return this._pending;
   }
@@ -454,6 +455,8 @@ class FileBrowserModel implements IDisposable, IPathTracker {
 defineSignal(FileBrowserModel.prototype, 'pathChanged');
 defineSignal(FileBrowserModel.prototype, 'refreshed');
 defineSignal(FileBrowserModel.prototype, 'fileChanged');
+defineSignal(FileBrowserModel.prototype, 'connectionFailure');
+
 
 /**
  * The namespace for the `FileBrowserModel` class statics.