Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e7136b1

Browse files
authored
fixed a bug (microsoft#12464)
1 parent 9004a55 commit e7136b1

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/client/datascience/export/exportBase.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,35 @@ export class ExportBase implements IExport {
2121
public async export(_source: Uri, _target: Uri): Promise<void> {}
2222

2323
@reportAction(ReportableAction.PerformingExport)
24-
public async executeCommand(source: Uri, args: string[]): Promise<void> {
24+
public async executeCommand(source: Uri, target: Uri, args: string[]): Promise<void> {
2525
const service = await this.getExecutionService(source);
2626
if (!service) {
2727
return;
2828
}
29-
await service.execModule('jupyter', ['nbconvert'].concat(args), { throwOnStdErr: false, encoding: 'utf8' });
29+
30+
const oldFileExists = await this.fileSystem.fileExists(target.fsPath);
31+
let oldFileTime;
32+
if (oldFileExists) {
33+
oldFileTime = (await this.fileSystem.stat(target.fsPath)).mtime;
34+
}
35+
36+
const result = await service.execModule('jupyter', ['nbconvert'].concat(args), {
37+
throwOnStdErr: false,
38+
encoding: 'utf8'
39+
});
40+
41+
// Need to check if export failed, since throwOnStdErr is not an
42+
// indicator of a failed export.
43+
if (!(await this.fileSystem.fileExists(target.fsPath))) {
44+
throw new Error(result.stderr);
45+
} else if (oldFileExists) {
46+
// If we exported to a file that already exists we need to check that
47+
// this file was actually overriden during export
48+
const newFileTime = (await this.fileSystem.stat(target.fsPath)).mtime;
49+
if (newFileTime === oldFileTime) {
50+
throw new Error(result.stderr);
51+
}
52+
}
3053
}
3154

3255
protected async getExecutionService(source: Uri): Promise<IPythonExecutionService | undefined> {

src/client/datascience/export/exportManagerFileOpener.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class ExportManagerFileOpener implements IExportManager {
3131
uri = await this.manager.export(format, model);
3232
} catch (e) {
3333
traceError('Export failed', e);
34-
await this.showExportFailed(e);
34+
this.showExportFailed(e);
3535
sendTelemetryEvent(Telemetry.ExportNotebookAsFailed, undefined, { format: format });
3636
return;
3737
} finally {
@@ -68,11 +68,13 @@ export class ExportManagerFileOpener implements IExportManager {
6868
await this.documentManager.showTextDocument(doc);
6969
}
7070

71-
private async showExportFailed(msg: string) {
72-
await this.applicationShell.showErrorMessage(
73-
// tslint:disable-next-line: messages-must-be-localized
74-
`${getLocString('DataScience.failedExportMessage', 'Export failed')} ${msg}`
75-
);
71+
private showExportFailed(msg: string) {
72+
this.applicationShell
73+
.showErrorMessage(
74+
// tslint:disable-next-line: messages-must-be-localized
75+
`${getLocString('DataScience.failedExportMessage', 'Export failed')} ${msg}`
76+
)
77+
.then();
7678
}
7779

7880
private async askOpenFile(uri: Uri): Promise<boolean> {

src/client/datascience/export/exportToHTML.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export class ExportToHTML extends ExportBase {
1515
'--output-dir',
1616
path.dirname(target.fsPath)
1717
];
18-
await this.executeCommand(source, args);
18+
await this.executeCommand(source, target, args);
1919
}
2020
}

0 commit comments

Comments
 (0)