Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLLS-226 properly cancel automatic Connection setup #617

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading