From 8b92a34cd9ff8de7586c21a943a85b181c2ac048 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 19 Jun 2020 18:08:29 -0400 Subject: [PATCH] fixed a bug --- src/client/datascience/export/exportBase.ts | 27 +++++++++++++++++-- .../export/exportManagerFileOpener.ts | 14 +++++----- src/client/datascience/export/exportToHTML.ts | 2 +- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/client/datascience/export/exportBase.ts b/src/client/datascience/export/exportBase.ts index 50bbc1a9b474..7bf957085fed 100644 --- a/src/client/datascience/export/exportBase.ts +++ b/src/client/datascience/export/exportBase.ts @@ -21,12 +21,35 @@ export class ExportBase implements IExport { public async export(_source: Uri, _target: Uri): Promise {} @reportAction(ReportableAction.PerformingExport) - public async executeCommand(source: Uri, args: string[]): Promise { + public async executeCommand(source: Uri, target: Uri, args: string[]): Promise { const service = await this.getExecutionService(source); if (!service) { return; } - await service.execModule('jupyter', ['nbconvert'].concat(args), { throwOnStdErr: false, encoding: 'utf8' }); + + const oldFileExists = await this.fileSystem.fileExists(target.fsPath); + let oldFileTime; + if (oldFileExists) { + oldFileTime = (await this.fileSystem.stat(target.fsPath)).mtime; + } + + const result = await service.execModule('jupyter', ['nbconvert'].concat(args), { + throwOnStdErr: false, + encoding: 'utf8' + }); + + // Need to check if export failed, since throwOnStdErr is not an + // indicator of a failed export. + if (!(await this.fileSystem.fileExists(target.fsPath))) { + throw new Error(result.stderr); + } else if (oldFileExists) { + // If we exported to a file that already exists we need to check that + // this file was actually overriden during export + const newFileTime = (await this.fileSystem.stat(target.fsPath)).mtime; + if (newFileTime === oldFileTime) { + throw new Error(result.stderr); + } + } } protected async getExecutionService(source: Uri): Promise { diff --git a/src/client/datascience/export/exportManagerFileOpener.ts b/src/client/datascience/export/exportManagerFileOpener.ts index 46ce79937709..7f5822883b1b 100644 --- a/src/client/datascience/export/exportManagerFileOpener.ts +++ b/src/client/datascience/export/exportManagerFileOpener.ts @@ -31,7 +31,7 @@ export class ExportManagerFileOpener implements IExportManager { uri = await this.manager.export(format, model); } catch (e) { traceError('Export failed', e); - await this.showExportFailed(e); + this.showExportFailed(e); sendTelemetryEvent(Telemetry.ExportNotebookAsFailed, undefined, { format: format }); return; } finally { @@ -68,11 +68,13 @@ export class ExportManagerFileOpener implements IExportManager { await this.documentManager.showTextDocument(doc); } - private async showExportFailed(msg: string) { - await this.applicationShell.showErrorMessage( - // tslint:disable-next-line: messages-must-be-localized - `${getLocString('DataScience.failedExportMessage', 'Export failed')} ${msg}` - ); + private showExportFailed(msg: string) { + this.applicationShell + .showErrorMessage( + // tslint:disable-next-line: messages-must-be-localized + `${getLocString('DataScience.failedExportMessage', 'Export failed')} ${msg}` + ) + .then(); } private async askOpenFile(uri: Uri): Promise { diff --git a/src/client/datascience/export/exportToHTML.ts b/src/client/datascience/export/exportToHTML.ts index 58c4d0987181..005addcc4cfc 100644 --- a/src/client/datascience/export/exportToHTML.ts +++ b/src/client/datascience/export/exportToHTML.ts @@ -15,6 +15,6 @@ export class ExportToHTML extends ExportBase { '--output-dir', path.dirname(target.fsPath) ]; - await this.executeCommand(source, args); + await this.executeCommand(source, target, args); } }