mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-16 17:22:29 -05:00
show error when scripting fails (#20843)
This commit is contained in:
@@ -37,55 +37,61 @@ const targetDatabaseEngineEditionMap = {
|
||||
11: 'SqlServerOnDemandEdition',
|
||||
};
|
||||
|
||||
const ScriptingFailedDialogTitle = nls.localize('scriptingFailed', "Scripting Failed");
|
||||
const SelectScriptNotGeneratedError = nls.localize('selectScriptNotGeneratedError', "Failed to generate select script for the selected object.");
|
||||
|
||||
/**
|
||||
* Select the top rows from an object
|
||||
*/
|
||||
export async function scriptSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<boolean> {
|
||||
const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
|
||||
let paramDetails = getScriptingParamDetails(connectionService, connectionResult, metadata)!;
|
||||
const result = await scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails);
|
||||
if (result && result.script) {
|
||||
const owner = await queryEditorService.newSqlEditor({ initalContent: result.script }, connectionProfile?.providerName);
|
||||
// Connect our editor to the input connection
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery, input: owner },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
const innerConnectionResult = await connectionService.connect(connectionProfile, owner.uri, options);
|
||||
|
||||
return Boolean(innerConnectionResult) && innerConnectionResult.connected;
|
||||
} else {
|
||||
let errMsg: string = nls.localize('scriptSelectNotFound', "No script was returned when calling select script on object ");
|
||||
throw new Error(errMsg.concat(metadata.metadataTypeName));
|
||||
export async function scriptSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService, errorMessageService: IErrorMessageService): Promise<void> {
|
||||
try {
|
||||
const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
|
||||
let paramDetails = getScriptingParamDetails(connectionService, connectionResult, metadata)!;
|
||||
const result = await scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails);
|
||||
if (result && result.script) {
|
||||
const owner = await queryEditorService.newSqlEditor({ initalContent: result.script }, connectionProfile?.providerName);
|
||||
// Connect our editor to the input connection
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery, input: owner },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
await connectionService.connect(connectionProfile, owner.uri, options);
|
||||
} else {
|
||||
throw new Error(SelectScriptNotGeneratedError);
|
||||
}
|
||||
} catch (err) {
|
||||
errorMessageService.showDialog(Severity.Error, ScriptingFailedDialogTitle, err?.message ?? err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a new Edit Data session
|
||||
*/
|
||||
export async function scriptEditSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<boolean> {
|
||||
const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
|
||||
let paramDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
|
||||
const result = await scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails!);
|
||||
if (result && result.script) {
|
||||
const owner = await queryEditorService.newEditDataEditor(metadata.schema, metadata.name, result.script);
|
||||
// Connect our editor
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
const innerConnectionResult = await connectionService.connect(connectionProfile, owner.uri, options);
|
||||
|
||||
return Boolean(innerConnectionResult) && innerConnectionResult.connected;
|
||||
} else {
|
||||
let errMsg: string = nls.localize('scriptSelectNotFound', "No script was returned when calling select script on object ");
|
||||
throw new Error(errMsg.concat(metadata.metadataTypeName));
|
||||
export async function scriptEditSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService, errorMessageService: IErrorMessageService): Promise<void> {
|
||||
try {
|
||||
const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
|
||||
let paramDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
|
||||
const result = await scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails!);
|
||||
if (result && result.script) {
|
||||
const owner = await queryEditorService.newEditDataEditor(metadata.schema, metadata.name, result.script);
|
||||
// Connect our editor
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
await connectionService.connect(connectionProfile, owner.uri, options);
|
||||
} else {
|
||||
throw new Error(SelectScriptNotGeneratedError);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
errorMessageService.showDialog(Severity.Error, ScriptingFailedDialogTitle, err?.message ?? err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,45 +124,44 @@ export async function script(connectionProfile: IConnectionProfile, metadata: az
|
||||
queryEditorService: IQueryEditorService,
|
||||
scriptingService: IScriptingService,
|
||||
operation: ScriptOperation,
|
||||
errorMessageService: IErrorMessageService): Promise<boolean> {
|
||||
const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
|
||||
let paramDetails = getScriptingParamDetails(connectionService, connectionResult, metadata)!;
|
||||
const result = await scriptingService.script(connectionResult, metadata, operation, paramDetails);
|
||||
if (result) {
|
||||
let script: string = result.script;
|
||||
|
||||
if (script) {
|
||||
let description = (metadata.schema && metadata.schema !== '') ? `${metadata.schema}.${metadata.name}` : metadata.name;
|
||||
const owner = await queryEditorService.newSqlEditor({ initalContent: script, description }, connectionProfile.providerName);
|
||||
// Connect our editor to the input connection
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
const innerConnectionResult = await connectionService.connect(connectionProfile, owner.uri, options);
|
||||
|
||||
return Boolean(innerConnectionResult) && innerConnectionResult.connected;
|
||||
errorMessageService: IErrorMessageService): Promise<void> {
|
||||
try {
|
||||
const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
|
||||
let paramDetails = getScriptingParamDetails(connectionService, connectionResult, metadata)!;
|
||||
const result = await scriptingService.script(connectionResult, metadata, operation, paramDetails);
|
||||
if (result) {
|
||||
let script: string = result.script;
|
||||
|
||||
if (script) {
|
||||
let description = (metadata.schema && metadata.schema !== '') ? `${metadata.schema}.${metadata.name}` : metadata.name;
|
||||
const owner = await queryEditorService.newSqlEditor({ initalContent: script, description }, connectionProfile.providerName);
|
||||
// Connect our editor to the input connection
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
await connectionService.connect(connectionProfile, owner.uri, options);
|
||||
} else {
|
||||
let scriptNotFoundMsg = nls.localize('scriptNotFoundForObject', "No script was returned when scripting as {0} on object {1}",
|
||||
GetScriptOperationName(operation), metadata.metadataTypeName);
|
||||
let messageDetail = '';
|
||||
let operationResult = scriptingService.getOperationFailedResult(result.operationId);
|
||||
if (operationResult && operationResult.hasError && operationResult.errorMessage) {
|
||||
scriptNotFoundMsg = operationResult.errorMessage;
|
||||
messageDetail = operationResult.errorDetails;
|
||||
}
|
||||
if (errorMessageService) {
|
||||
errorMessageService.showDialog(Severity.Error, ScriptingFailedDialogTitle, scriptNotFoundMsg, messageDetail);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let scriptNotFoundMsg = nls.localize('scriptNotFoundForObject', "No script was returned when scripting as {0} on object {1}",
|
||||
GetScriptOperationName(operation), metadata.metadataTypeName);
|
||||
let messageDetail = '';
|
||||
let operationResult = scriptingService.getOperationFailedResult(result.operationId);
|
||||
if (operationResult && operationResult.hasError && operationResult.errorMessage) {
|
||||
scriptNotFoundMsg = operationResult.errorMessage;
|
||||
messageDetail = operationResult.errorDetails;
|
||||
}
|
||||
if (errorMessageService) {
|
||||
let title = nls.localize('scriptingFailed', "Scripting Failed");
|
||||
errorMessageService.showDialog(Severity.Error, title, scriptNotFoundMsg, messageDetail);
|
||||
}
|
||||
throw new Error(scriptNotFoundMsg);
|
||||
throw new Error(nls.localize('scriptNotFound', "No script was returned when scripting as {0}", GetScriptOperationName(operation)));
|
||||
}
|
||||
} else {
|
||||
throw new Error(nls.localize('scriptNotFound', "No script was returned when scripting as {0}", GetScriptOperationName(operation)));
|
||||
} catch (err) {
|
||||
errorMessageService.showDialog(Severity.Error, ScriptingFailedDialogTitle, err?.message ?? err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user