Handle error cases properly (#23322)

This commit is contained in:
Cheena Malhotra
2023-06-06 08:18:49 -07:00
committed by GitHub
parent 02a62a430f
commit 85dcec51ac
2 changed files with 67 additions and 64 deletions

View File

@@ -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);
} }

View File

@@ -605,7 +605,8 @@ 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`);
} return connectionResult;
} else {
// 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.tryAddActiveConnection(connectionMgmtInfo, connection, options.saveTheConnection); this.tryAddActiveConnection(connectionMgmtInfo, connection, options.saveTheConnection);
@@ -642,6 +643,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
} else { } else {
return connectionResult; 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 => {
if (callbacks.onConnectReject) { if (callbacks.onConnectReject) {
@@ -728,7 +730,7 @@ 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);
} }
@@ -760,6 +762,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
}); });
} }
} }
}
public getConnectionIconId(connectionId: string): string { public getConnectionIconId(connectionId: string): string {
if (!connectionId || !this._mementoObj || !this._mementoObj.CONNECTION_ICON_ID) { if (!connectionId || !this._mementoObj || !this._mementoObj.CONNECTION_ICON_ID) {