Kaynağa Gözat

Handle MIME model render failures in the MIME document widget.

Afshin Darian 7 yıl önce
ebeveyn
işleme
98a82a0d17
1 değiştirilmiş dosya ile 19 ekleme ve 10 silme
  1. 19 10
      packages/docregistry/src/mimedocument.ts

+ 19 - 10
packages/docregistry/src/mimedocument.ts

@@ -1,6 +1,18 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import {
+  showErrorMessage
+} from '@jupyterlab/apputils';
+
+import {
+  ActivityMonitor, PathExt
+} from '@jupyterlab/coreutils';
+
+import {
+  IRenderMime, RenderMimeRegistry, MimeModel
+} from '@jupyterlab/rendermime';
+
 import {
   JSONObject, PromiseDelegate
 } from '@phosphor/coreutils';
@@ -13,14 +25,6 @@ import {
   BoxLayout, Widget
 } from '@phosphor/widgets';
 
-import {
-  ActivityMonitor, PathExt
-} from '@jupyterlab/coreutils';
-
-import {
-  IRenderMime, RenderMimeRegistry, MimeModel
-} from '@jupyterlab/rendermime';
-
 import {
   ABCWidgetFactory
 } from './default';
@@ -67,7 +71,7 @@ class MimeDocument extends Widget implements DocumentRegistry.IReadyWidget {
       if (this.isDisposed) {
         return;
       }
-      return this._render().then();
+      return this._render();
     }).then(() => {
       // Throttle the rendering rate of the widget.
       this._monitor = new ActivityMonitor({
@@ -164,8 +168,13 @@ class MimeDocument extends Widget implements DocumentRegistry.IReadyWidget {
       this._hasRendered = true;
       this._isRendering = false;
       if (this._renderRequested) {
-        this._render();
+        return this._render();
       }
+    }).catch(reason => {
+      // Dispose the document if rendering fails.
+      requestAnimationFrame(() => { this.dispose(); });
+
+      showErrorMessage(`Renderer Failure: ${context.path}`, reason);
     });
   }