handle table designer errors (#22527)

* handle table designer error

* log to console
This commit is contained in:
Alan Ren
2023-03-29 16:37:15 -07:00
committed by GitHub
parent 4458a5bd57
commit ff603fa911

View File

@@ -11,53 +11,70 @@ import { generateUuid } from 'vscode-languageclient/lib/utils/uuid';
import { fillServerInfo } from '../telemetry'; import { fillServerInfo } from '../telemetry';
import * as telemetry from '@microsoft/ads-extension-telemetry'; import * as telemetry from '@microsoft/ads-extension-telemetry';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
import { getConfigPreloadDatabaseModel, setConfigPreloadDatabaseModel } from '../utils'; import { getConfigPreloadDatabaseModel, getErrorMessage, setConfigPreloadDatabaseModel } from '../utils';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
const NewTableText = localize('tableDesigner.NewTable', "New Table"); const NewTableText = localize('tableDesigner.NewTable', "New Table");
const DidInformUserKey: string = 'tableDesigner.DidInformUser'; const DidInformUserKey: string = 'tableDesigner.DidInformUser';
const FailedToGetConnectionStringError = localize('tableDesigner.FailedToGetConnectionStringError', "Failed to get connection string for the table. Please reconnect to the server and try again.");
export function registerTableDesignerCommands(appContext: AppContext) { export function registerTableDesignerCommands(appContext: AppContext) {
appContext.extensionContext.subscriptions.push(vscode.commands.registerCommand('mssql.newTable', async (context: azdata.ObjectExplorerContext) => { appContext.extensionContext.subscriptions.push(vscode.commands.registerCommand('mssql.newTable', async (context: azdata.ObjectExplorerContext) => {
void showPreloadDbModelSettingPrompt(appContext); try {
const connectionString = await azdata.connection.getConnectionString(context.connectionProfile!.id, true); void showPreloadDbModelSettingPrompt(appContext);
const tableIcon = context.nodeInfo!.nodeSubType as azdata.designers.TableIcon; const connectionString = await azdata.connection.getConnectionString(context.connectionProfile!.id, true);
const telemetryInfo = await getTelemetryInfo(context, tableIcon); if (!connectionString) {
await azdata.designers.openTableDesigner(sqlProviderName, { throw new Error(FailedToGetConnectionStringError);
title: NewTableText, }
tooltip: `${context.connectionProfile!.serverName} - ${context.connectionProfile!.databaseName} - ${NewTableText}`, const tableIcon = context.nodeInfo!.nodeSubType as azdata.designers.TableIcon;
server: context.connectionProfile!.serverName, const telemetryInfo = await getTelemetryInfo(context, tableIcon);
database: context.connectionProfile!.databaseName, await azdata.designers.openTableDesigner(sqlProviderName, {
isNewTable: true, title: NewTableText,
id: generateUuid(), tooltip: `${context.connectionProfile!.serverName} - ${context.connectionProfile!.databaseName} - ${NewTableText}`,
connectionString: connectionString, server: context.connectionProfile!.serverName,
accessToken: context.connectionProfile!.options.azureAccountToken, database: context.connectionProfile!.databaseName,
tableIcon: tableIcon isNewTable: true,
}, telemetryInfo); id: generateUuid(),
connectionString: connectionString,
accessToken: context.connectionProfile!.options.azureAccountToken,
tableIcon: tableIcon
}, telemetryInfo);
} catch (error) {
console.error(error);
await vscode.window.showErrorMessage(getErrorMessage(error), { modal: true });
}
})); }));
appContext.extensionContext.subscriptions.push(vscode.commands.registerCommand('mssql.designTable', async (context: azdata.ObjectExplorerContext) => { appContext.extensionContext.subscriptions.push(vscode.commands.registerCommand('mssql.designTable', async (context: azdata.ObjectExplorerContext) => {
void showPreloadDbModelSettingPrompt(appContext); try {
const server = context.connectionProfile!.serverName; void showPreloadDbModelSettingPrompt(appContext);
const database = context.connectionProfile!.databaseName; const server = context.connectionProfile!.serverName;
const schema = context.nodeInfo!.metadata!.schema; const database = context.connectionProfile!.databaseName;
const name = context.nodeInfo!.metadata!.name; const schema = context.nodeInfo!.metadata!.schema;
const connectionString = await azdata.connection.getConnectionString(context.connectionProfile!.id, true); const name = context.nodeInfo!.metadata!.name;
const tableIcon = context.nodeInfo!.nodeSubType as azdata.designers.TableIcon; const connectionString = await azdata.connection.getConnectionString(context.connectionProfile!.id, true);
const telemetryInfo = await getTelemetryInfo(context, tableIcon); if (connectionString) {
await azdata.designers.openTableDesigner(sqlProviderName, { throw new Error(FailedToGetConnectionStringError);
title: `${schema}.${name}`, }
tooltip: `${server} - ${database} - ${schema}.${name}`, const tableIcon = context.nodeInfo!.nodeSubType as azdata.designers.TableIcon;
server: server, const telemetryInfo = await getTelemetryInfo(context, tableIcon);
database: database, await azdata.designers.openTableDesigner(sqlProviderName, {
isNewTable: false, title: `${schema}.${name}`,
name: name, tooltip: `${server} - ${database} - ${schema}.${name}`,
schema: schema, server: server,
id: `${sqlProviderName}|${server}|${database}|${schema}|${name}`, database: database,
connectionString: connectionString, isNewTable: false,
accessToken: context.connectionProfile!.options.azureAccountToken, name: name,
tableIcon: tableIcon schema: schema,
}, telemetryInfo); id: `${sqlProviderName}|${server}|${database}|${schema}|${name}`,
connectionString: connectionString,
accessToken: context.connectionProfile!.options.azureAccountToken,
tableIcon: tableIcon
}, telemetryInfo);
} catch (error) {
console.error(error);
await vscode.window.showErrorMessage(getErrorMessage(error), { modal: true });
}
})); }));
} }