From 472c9decfa6a3cbaae4f296761841df552d8bb70 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Tue, 17 Nov 2020 10:03:33 -0800 Subject: [PATCH] Display error when doing notebook convert (#13438) * Display error when doing notebook convert * Update STS --- extensions/mssql/config.json | 2 +- extensions/mssql/src/main.ts | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/extensions/mssql/config.json b/extensions/mssql/config.json index f6e0aa5fb8..cd646e7eb5 100644 --- a/extensions/mssql/config.json +++ b/extensions/mssql/config.json @@ -1,6 +1,6 @@ { "downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/v{#version#}/microsoft.sqltools.servicelayer-{#fileName#}", - "version": "3.0.0-release.52", + "version": "3.0.0-release.56", "downloadFileNames": { "Windows_86": "win-x86-netcoreapp3.1.zip", "Windows_64": "win-x64-netcoreapp3.1.zip", diff --git a/extensions/mssql/src/main.ts b/extensions/mssql/src/main.ts index 7daa5aaf3c..22941da135 100644 --- a/extensions/mssql/src/main.ts +++ b/extensions/mssql/src/main.ts @@ -81,21 +81,29 @@ export async function activate(context: vscode.ExtensionContext): Promise { - const result = await appContext.getService(Constants.NotebookConvertService).convertSqlToNotebook(uri.toString()); - const title = findNextUntitledEditorName(); - const untitledUri = vscode.Uri.parse(`untitled:${title}`); - await azdata.nb.showNotebookDocument(untitledUri, { initialContent: result.content }); + try { + const result = await appContext.getService(Constants.NotebookConvertService).convertSqlToNotebook(uri.toString()); + const title = findNextUntitledEditorName(); + const untitledUri = vscode.Uri.parse(`untitled:${title}`); + await azdata.nb.showNotebookDocument(untitledUri, { initialContent: result.content }); + } catch (err) { + vscode.window.showErrorMessage(localize('mssql.errorConvertingToNotebook', "An error occurred converting the SQL document to a Notebook. Error : {0}", err.toString())); + } }); vscode.commands.registerCommand('mssql.exportNotebookToSql', async (uri: vscode.Uri) => { - // SqlToolsService doesn't currently store anything about Notebook documents so we have to pass the raw JSON to it directly - // We use vscode.workspace.textDocuments here because the azdata.nb.notebookDocuments don't actually contain their contents - // (they're left out for perf purposes) - const doc = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === uri.toString()); - const result = await appContext.getService(Constants.NotebookConvertService).convertNotebookToSql(doc.getText()); + try { + // SqlToolsService doesn't currently store anything about Notebook documents so we have to pass the raw JSON to it directly + // We use vscode.workspace.textDocuments here because the azdata.nb.notebookDocuments don't actually contain their contents + // (they're left out for perf purposes) + const doc = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === uri.toString()); + const result = await appContext.getService(Constants.NotebookConvertService).convertNotebookToSql(doc.getText()); - const sqlDoc = await vscode.workspace.openTextDocument({ language: 'sql', content: result.content }); - await vscode.commands.executeCommand('vscode.open', sqlDoc.uri); + const sqlDoc = await vscode.workspace.openTextDocument({ language: 'sql', content: result.content }); + await vscode.commands.executeCommand('vscode.open', sqlDoc.uri); + } catch (err) { + vscode.window.showErrorMessage(localize('mssql.errorConvertingToSQL', "An error occurred converting the Notebook document to SQL. Error : {0}", err.toString())); + } }); return createMssqlApi(appContext);