Skip to content

Commit

Permalink
fix: improve disconnected action error messages VSCODE-112 (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anemy authored Dec 7, 2022
1 parent 2fed1fd commit 18504a2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/editors/collectionDocumentsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@ export default class CollectionViewProvider
// Ensure we're still connected to the correct connection.
if (connectionId !== this._connectionController.getActiveConnectionId()) {
operation.isCurrentlyFetchingMoreDocuments = false;
const oldConnectionName =
this._connectionController.getSavedConnectionName(connectionId || '') ||
'the database';
void vscode.window.showErrorMessage(
`Unable to list documents: no longer connected to ${connectionId}`
`Unable to list documents: no longer connected to ${oldConnectionName}`
);

throw new Error(
`Unable to list documents: no longer connected to ${connectionId}`
`Unable to list documents: no longer connected to ${oldConnectionName}`
);
}

Expand All @@ -74,7 +77,7 @@ export default class CollectionViewProvider
const dataservice = this._connectionController.getActiveDataService();

if (dataservice === null) {
const errorMessage = `Unable to list documents: no longer connected to ${connectionId}`;
const errorMessage = 'Unable to list documents: no longer connected';

void vscode.window.showErrorMessage(errorMessage);

Expand Down
6 changes: 5 additions & 1 deletion src/editors/editorsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,12 @@ export default class EditorsController {

// Ensure we're still connected to the correct connection.
if (connectionId !== this._connectionController.getActiveConnectionId()) {
const oldConnectionName =
this._connectionController.getSavedConnectionName(connectionId || '') ||
'the database';

void vscode.window.showErrorMessage(
`Unable to view more documents: no longer connected to ${connectionId}`
`Unable to view more documents: no longer connected to ${oldConnectionName}`
);

return Promise.resolve(false);
Expand Down
2 changes: 1 addition & 1 deletion src/editors/mongoDBDocumentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default class MongoDBDocumentService {
this._connectionController.getActiveConnectionId();
const connectionName = connectionId
? this._connectionController.getSavedConnectionName(connectionId)
: '';
: 'the database';

if (activeConnectionId !== connectionId) {
return this._fetchDocumentFailed(
Expand Down

0 comments on commit 18504a2

Please sign in to comment.