Browse Source

Merge pull request #3612 from afshin/restore-fix

Handle errors when rendering MIME documents.
Ian Rose 7 years ago
parent
commit
d6db34196a
2 changed files with 23 additions and 10 deletions
  1. 19 10
      packages/docregistry/src/mimedocument.ts
  2. 4 0
      packages/vega2-extension/src/index.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);
     });
   }
 

+ 4 - 0
packages/vega2-extension/src/index.ts

@@ -103,6 +103,10 @@ class RenderedVega extends Widget implements IRenderMime.IRenderer {
     return Private.ensureMod().then(embedFunc => {
       return new Promise<void>((resolve, reject) => {
         embedFunc(this.node, embedSpec, (error: any, result: any): any => {
+          if (error) {
+            return reject(error);
+          }
+
           // Save png data in MIME bundle along with original MIME data.
           if (!model.data['image/png']) {
             let imageData = result.view.toImageURL().split(',')[1] as JSONValue;