Skip to content

Commit

Permalink
feat(connections): nice error message when connecting to Stream Proce…
Browse files Browse the repository at this point in the history
…ssing COMPASS-7809 (#5678)

* feat: Nice error message when connecting to Stream Processing COMPASS-7809

* update message
  • Loading branch information
mcasimir authored Apr 17, 2024
1 parent 390c921 commit 189bcd9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/compass-connections/src/connections-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,31 @@ describe('ConnectionsManager', function () {
}
);

context('when connecting to Atlas Streams', function () {
beforeEach(function () {
connectionsManager = getConnectionsManager(mockConnectFn);
});

it('should throw an error', async function () {
const maybeError = await connectionsManager
.connect(
{
id: '1',
connectionOptions: {
connectionString:
'mongodb://atlas-stream-example.mongodb.net/?tls=true',
},
},
getConnectionConfigurationOptions()
)
.catch((error) => error);

expect(maybeError.message).to.equal(
'Atlas Stream Processing is not yet supported on MongoDB Compass. To work with your Stream Processing Instance, connect with mongosh or MongoDB for VS Code.'
);
});
});

context('when a connection attempt is cancelled', function () {
let canceledPromise;
beforeEach(function () {
Expand Down
24 changes: 24 additions & 0 deletions packages/compass-connections/src/connections-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
import { mongoLogId } from '@mongodb-js/compass-logging/provider';
import { cloneDeep, merge } from 'lodash';
import { adjustConnectionOptionsBeforeConnect } from '@mongodb-js/connection-form';
import mongodbBuildInfo from 'mongodb-build-info';

type ConnectFn = typeof connect;
type ConnectionInfoId = ConnectionInfo['id'];
Expand Down Expand Up @@ -212,6 +213,14 @@ export class ConnectionsManager extends EventEmitter {

this.connectionAttempts.set(connectionId, connectionAttempt);

// Temporarily disable Atlas Streams connections until https://jira.mongodb.org/browse/STREAMS-862
// is done.
if (isAtlasStreamsInstance(adjustedConnectionInfoForConnection)) {
throw new Error(
'Atlas Stream Processing is not yet supported on MongoDB Compass. To work with your Stream Processing Instance, connect with mongosh or MongoDB for VS Code.'
);
}

const dataService = await connectionAttempt.connect(
adjustedConnectionInfoForConnection.connectionOptions
);
Expand Down Expand Up @@ -355,3 +364,18 @@ export class ConnectionsManager extends EventEmitter {
this.emit(connectionEvent, ...connectionEventParams);
}
}

function isAtlasStreamsInstance(
adjustedConnectionInfoForConnection: ConnectionInfo
) {
try {
return mongodbBuildInfo.isAtlasStream(
adjustedConnectionInfoForConnection.connectionOptions.connectionString
);
} catch {
// This catch-all is not ideal, but it safe-guards regular connections
// instead of making assumptions on the fact that the implementation
// of `mongodbBuildInfo.isAtlasStream` would never throw.
return false;
}
}

0 comments on commit 189bcd9

Please sign in to comment.