mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Handle error cases properly (#23322)
This commit is contained in:
@@ -860,7 +860,7 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const result = await this.connectionManagementService.listDatabases(uri);
|
const result = await this.connectionManagementService.listDatabases(uri);
|
||||||
return result.databaseNames;
|
return result?.databaseNames ?? [];
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logService.error(`Error loading database names for query editor `, err);
|
this.logService.error(`Error loading database names for query editor `, err);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -605,42 +605,44 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
let connectionMgmtInfo = this._connectionStatusManager.findConnection(uri);
|
let connectionMgmtInfo = this._connectionStatusManager.findConnection(uri);
|
||||||
if (!connectionMgmtInfo) {
|
if (!connectionMgmtInfo) {
|
||||||
this._logService.info(`Could not find connection management info for ${uri} after connection`);
|
this._logService.info(`Could not find connection management info for ${uri} after connection`);
|
||||||
}
|
|
||||||
// Currently this could potentially throw an error because it expects there to always be
|
|
||||||
// a connection management info. See https://github.com/microsoft/azuredatastudio/issues/16556
|
|
||||||
this.tryAddActiveConnection(connectionMgmtInfo, connection, options.saveTheConnection);
|
|
||||||
|
|
||||||
if (callbacks.onConnectSuccess) {
|
|
||||||
callbacks.onConnectSuccess(options.params, connectionResult.connectionProfile);
|
|
||||||
}
|
|
||||||
if (options.saveTheConnection || isEdit) {
|
|
||||||
|
|
||||||
await this.saveToSettings(uri, connection, matcher).then(value => {
|
|
||||||
this._onAddConnectionProfile.fire(connection);
|
|
||||||
if (isEdit) {
|
|
||||||
this._onConnectionProfileEdited.fire({
|
|
||||||
oldProfileId: options.params.oldProfileId,
|
|
||||||
profile: <ConnectionProfile>connection
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (options.params === undefined) {
|
|
||||||
this._onConnectionProfileConnected.fire(<ConnectionProfile>connection);
|
|
||||||
} else {
|
|
||||||
this._onConnectionProfileCreated.fire(<ConnectionProfile>connection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.doActionsAfterConnectionComplete(value, options);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
connection.saveProfile = false;
|
|
||||||
this.doActionsAfterConnectionComplete(uri, options);
|
|
||||||
}
|
|
||||||
if (connection.savePassword) {
|
|
||||||
return this._connectionStore.savePassword(connection).then(() => {
|
|
||||||
return connectionResult;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return connectionResult;
|
return connectionResult;
|
||||||
|
} else {
|
||||||
|
// Currently this could potentially throw an error because it expects there to always be
|
||||||
|
// a connection management info. See https://github.com/microsoft/azuredatastudio/issues/16556
|
||||||
|
this.tryAddActiveConnection(connectionMgmtInfo, connection, options.saveTheConnection);
|
||||||
|
|
||||||
|
if (callbacks.onConnectSuccess) {
|
||||||
|
callbacks.onConnectSuccess(options.params, connectionResult.connectionProfile);
|
||||||
|
}
|
||||||
|
if (options.saveTheConnection || isEdit) {
|
||||||
|
|
||||||
|
await this.saveToSettings(uri, connection, matcher).then(value => {
|
||||||
|
this._onAddConnectionProfile.fire(connection);
|
||||||
|
if (isEdit) {
|
||||||
|
this._onConnectionProfileEdited.fire({
|
||||||
|
oldProfileId: options.params.oldProfileId,
|
||||||
|
profile: <ConnectionProfile>connection
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (options.params === undefined) {
|
||||||
|
this._onConnectionProfileConnected.fire(<ConnectionProfile>connection);
|
||||||
|
} else {
|
||||||
|
this._onConnectionProfileCreated.fire(<ConnectionProfile>connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.doActionsAfterConnectionComplete(value, options);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
connection.saveProfile = false;
|
||||||
|
this.doActionsAfterConnectionComplete(uri, options);
|
||||||
|
}
|
||||||
|
if (connection.savePassword) {
|
||||||
|
return this._connectionStore.savePassword(connection).then(() => {
|
||||||
|
return connectionResult;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return connectionResult;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (connectionResult && connectionResult.errorMessage) {
|
} else if (connectionResult && connectionResult.errorMessage) {
|
||||||
return this.handleConnectionError(connection, uri, options, callbacks, connectionResult).catch(handleConnectionError => {
|
return this.handleConnectionError(connection, uri, options, callbacks, connectionResult).catch(handleConnectionError => {
|
||||||
@@ -728,36 +730,37 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
// Currently this could potentially throw an error because it expects there to always be
|
// Currently this could potentially throw an error because it expects there to always be
|
||||||
// a connection management info. See https://github.com/microsoft/azuredatastudio/issues/16556
|
// a connection management info. See https://github.com/microsoft/azuredatastudio/issues/16556
|
||||||
this._logService.info(`Could not find connection management info for ${uri} after connection complete`);
|
this._logService.info(`Could not find connection management info for ${uri} after connection complete`);
|
||||||
}
|
} else {
|
||||||
if (options.showDashboard) {
|
if (options.showDashboard) {
|
||||||
this.showDashboardForConnectionManagementInfo(connectionManagementInfo.connectionProfile);
|
this.showDashboardForConnectionManagementInfo(connectionManagementInfo.connectionProfile);
|
||||||
}
|
|
||||||
|
|
||||||
let connectionProfile = connectionManagementInfo.connectionProfile;
|
|
||||||
this._onConnect.fire(<IConnectionParams>{
|
|
||||||
connectionUri: uri,
|
|
||||||
connectionProfile: connectionProfile
|
|
||||||
});
|
|
||||||
|
|
||||||
let iconProvider = this._iconProviders.get(connectionManagementInfo.providerId);
|
|
||||||
if (iconProvider) {
|
|
||||||
const serverInfo: azdata.ServerInfo | undefined = this.getServerInfo(connectionProfile.id);
|
|
||||||
if (!serverInfo) {
|
|
||||||
this._logService.warn(`Could not find ServerInfo for connection ${connectionProfile.id} when updating icon`);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
const profile: interfaces.IConnectionProfile = connectionProfile.toIConnectionProfile();
|
|
||||||
iconProvider.getConnectionIconId(profile, serverInfo).then(iconId => {
|
let connectionProfile = connectionManagementInfo.connectionProfile;
|
||||||
if (iconId && this._mementoObj && this._mementoContext) {
|
this._onConnect.fire(<IConnectionParams>{
|
||||||
if (!this._mementoObj.CONNECTION_ICON_ID) {
|
connectionUri: uri,
|
||||||
this._mementoObj.CONNECTION_ICON_ID = <any>{};
|
connectionProfile: connectionProfile
|
||||||
}
|
|
||||||
if (this._mementoObj.CONNECTION_ICON_ID[connectionProfile.id] !== iconId) {
|
|
||||||
this._mementoObj.CONNECTION_ICON_ID[connectionProfile.id] = iconId;
|
|
||||||
this._mementoContext.saveMemento();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let iconProvider = this._iconProviders.get(connectionManagementInfo.providerId);
|
||||||
|
if (iconProvider) {
|
||||||
|
const serverInfo: azdata.ServerInfo | undefined = this.getServerInfo(connectionProfile.id);
|
||||||
|
if (!serverInfo) {
|
||||||
|
this._logService.warn(`Could not find ServerInfo for connection ${connectionProfile.id} when updating icon`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const profile: interfaces.IConnectionProfile = connectionProfile.toIConnectionProfile();
|
||||||
|
iconProvider.getConnectionIconId(profile, serverInfo).then(iconId => {
|
||||||
|
if (iconId && this._mementoObj && this._mementoContext) {
|
||||||
|
if (!this._mementoObj.CONNECTION_ICON_ID) {
|
||||||
|
this._mementoObj.CONNECTION_ICON_ID = <any>{};
|
||||||
|
}
|
||||||
|
if (this._mementoObj.CONNECTION_ICON_ID[connectionProfile.id] !== iconId) {
|
||||||
|
this._mementoObj.CONNECTION_ICON_ID[connectionProfile.id] = iconId;
|
||||||
|
this._mementoContext.saveMemento();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user