Skip to content

Commit

Permalink
SLLS-226 properly cancel automatic Connection setup
Browse files Browse the repository at this point in the history
  • Loading branch information
sophio-japharidze-sonarsource committed Aug 29, 2024
1 parent 1746afb commit 6eed6c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/connected/automaticConnectionCancellationError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class AutomaticConnectionSetupCancellationError extends Error {
constructor(message: string) {
super(message);
this.name = "AutomaticConnectionSetupCancellationError";
}
}
17 changes: 13 additions & 4 deletions src/connected/connectionsetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { escapeHtml, ResourceResolver } from '../util/webview';
import { DEFAULT_CONNECTION_ID } from '../commons';
import { BindingService } from './binding';
import TRIGGER_HELP_AND_FEEDBACK_LINK = Commands.TRIGGER_HELP_AND_FEEDBACK_LINK;
import { AutomaticConnectionSetupCancellationError } from './automaticConnectionCancellationError';

let connectionSetupPanel: vscode.WebviewPanel;

Expand All @@ -48,7 +49,15 @@ const SONARCLOUD_DESCRIPTION =

export function assistCreatingConnection(context: vscode.ExtensionContext) {
return async assistCreatingConnectionParams => {
return { newConnectionId: await confirmConnectionDetailsAndSave(context)(assistCreatingConnectionParams.isSonarCloud, assistCreatingConnectionParams.serverUrlOrOrganisationKey, assistCreatingConnectionParams.token) }
let newConnectionId : string | null;
try {
newConnectionId = await confirmConnectionDetailsAndSave(context)(assistCreatingConnectionParams.isSonarCloud, assistCreatingConnectionParams.serverUrlOrOrganisationKey, assistCreatingConnectionParams.token);
} catch (error) {
if (error instanceof AutomaticConnectionSetupCancellationError) {
return null;
}
}
return { newConnectionId }
};
}

Expand Down Expand Up @@ -110,13 +119,13 @@ export function confirmConnectionDetailsAndSave(context: vscode.ExtensionContext
} else {
// old flow for SonarQube
connectToSonarQube(context)(serverUrlOrOrganizationKey);
return null;
throw new AutomaticConnectionSetupCancellationError('Automatic Connection setup cancelled; User will manually enter token');
}
} else if (!reply.confirmed && !reply.cancelled) {
vscode.commands.executeCommand(TRIGGER_HELP_AND_FEEDBACK_LINK, 'connectedModeDocs');
return null;
throw new AutomaticConnectionSetupCancellationError('Automatic Connection setup was cancelled; Opening documentation');
}
return null;
throw new AutomaticConnectionSetupCancellationError('Automatic Connection setup was cancelled by the user')
}
}

Expand Down

0 comments on commit 6eed6c2

Please sign in to comment.