From 9d9d973ff459994acf3e78a72536d80e00f823b5 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Tue, 10 Dec 2024 17:54:29 +1100 Subject: [PATCH] Log and display errors when failing to export plot --- .../plotView/rendererCommunication.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/webviews/extension-side/plotView/rendererCommunication.ts b/src/webviews/extension-side/plotView/rendererCommunication.ts index 8f461bfefab..75267f9376f 100644 --- a/src/webviews/extension-side/plotView/rendererCommunication.ts +++ b/src/webviews/extension-side/plotView/rendererCommunication.ts @@ -10,6 +10,8 @@ import { IDisposable } from '../../../platform/common/types'; import { noop } from '../../../platform/common/utils/misc'; import { PlotViewHandler } from './plotViewHandler'; import { IPlotSaveHandler } from './types'; +import { logger } from '../../../platform/logging'; +import { DataScience } from '../../../platform/common/utils/localize'; export type OpenImageInPlotViewer = { type: 'openImageInPlotViewer'; @@ -48,15 +50,20 @@ export class RendererCommunication implements IExtensionSyncActivationService, I onDidReceiveMessage: Event<{ editor: NotebookEditor; message: OpenImageInPlotViewer | SaveImageAs }>; }; api.onDidReceiveMessage( - ({ editor, message }) => { + async ({ editor, message }) => { const document = editor.notebook || window.activeNotebookEditor?.notebook; if (!document) { return; } - if (message.type === 'saveImageAs') { - this.plotSaveHandler.savePlot(document, message.outputId, message.mimeType).catch(noop); - } else if (message.type === 'openImageInPlotViewer') { - this.plotViewHandler.openPlot(document, message.outputId).catch(noop); + try { + if (message.type === 'saveImageAs') { + await this.plotSaveHandler.savePlot(document, message.outputId, message.mimeType); + } else if (message.type === 'openImageInPlotViewer') { + await this.plotViewHandler.openPlot(document, message.outputId); + } + } catch (ex) { + logger.error(ex); + window.showErrorMessage(DataScience.exportImageFailed(ex)).then(noop, noop); } }, this,