Skip to content

vscode uri handler now asks for signing in to another account instead…#2899

Open
mkrueger wants to merge 1 commit intomainfrom
dev/mkrueger/issue2686
Open

vscode uri handler now asks for signing in to another account instead…#2899
mkrueger wants to merge 1 commit intomainfrom
dev/mkrueger/issue2686

Conversation

@mkrueger
Copy link
Member

This pull request enhances the robustness and user experience of the Cosmos DB "Open in VS Code" URI handler, especially around Azure account and subscription issues. It introduces improved error handling and user prompts when resources cannot be found due to account or subscription mismatches, and adds comprehensive tests for these scenarios. Additionally, it updates localization strings to provide clearer guidance to users.

Improvements to Azure account/subscription handling:

  • Refactored revealAzureResourceInExplorer in src/vscodeUriHandler.ts to detect when a resource cannot be found due to account or subscription issues, prompting the user to sign in or select subscriptions, and retrying the reveal operation after user action. [1] [2]
  • Added helper functions promptToFixAzureAccountAccess and revealAzureResourceWithAccountPrompt to encapsulate user prompting and retry logic for account/subscription issues.
  • Improved error message handling in globalUriHandler to properly propagate UserCancelledError and provide more descriptive failure messages.

Localization and messaging updates:

  • Updated and added several localization strings in l10n/bundle.l10n.json to clarify instructions when resources are not found due to Azure account or subscription problems, and to support new prompts for sign-in and subscription selection. [1] [2] [3] [4] [5]

Testing improvements:

  • Added a new test suite in test/vscodeUriHandler.test.ts to verify that the handler correctly prompts users and retries when encountering subscription/account issues, and that cancellation is handled as expected.

Other changes:

  • Exported globalUriHandler from extension.bundle.ts to make it available for testing and integration.
  • Minor import adjustment to include parseError in src/vscodeUriHandler.ts.… of showing a "subscription not found" error.

fixes #2686

image

… of showing a "subscription not found" error.

fixes #2686
@mkrueger mkrueger requested a review from a team as a code owner January 20, 2026 14:20
@sevoku sevoku requested a review from Copilot January 22, 2026 21:14
@sevoku
Copy link
Member

sevoku commented Jan 22, 2026

I have not tested this yet, but we should not forget to add tenantId param to the Azure Portal, that's an essential part.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves the Cosmos DB “Open in VS Code” URI handler to better handle Azure account/subscription mismatches by prompting the user to sign in or select subscriptions and retrying the reveal flow, with updated messaging and tests.

Changes:

  • Add account/subscription mismatch prompting + retry logic around revealAzureResource / tree lookup.
  • Improve URI handler error propagation to preserve UserCancelledError (avoid wrapping as a generic failure).
  • Add localization strings and a new test suite covering the new prompts/retry behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/vscodeUriHandler.ts Adds prompt/retry helpers for subscription-not-found and account-mismatch scenarios; preserves UserCancelledError propagation.
l10n/bundle.l10n.json Adds/updates strings for new prompts and improved “resource not found” guidance.
test/vscodeUriHandler.test.ts Adds tests for subscription-not-found prompt + retry, account mismatch retry, and cancellation handling.
extension.bundle.ts Exports globalUriHandler for test access.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +89 to +96
// Simulate the user dismissing the prompt by having `context.ui.showWarningMessage` cancel.
// The test input infrastructure can't return "undefined" from `showWarningMessage`,
// so we simulate cancel by throwing `UserCancelledError`.
ext.rgApiV2 = {
resources: {
revealAzureResource: async () => {
throw new UserCancelledError('subscriptionNotFound');
},
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cancellation test doesn’t actually exercise the new “user dismissed the subscription/account prompt” path (choice being undefined leading to new UserCancelledError(...)). Instead it forces revealAzureResource to throw UserCancelledError, and it also has no assertion that an error notification wasn’t shown. Consider stubbing context.ui.showWarningMessage to return undefined via an onActionStart handler and asserting that no wrapped/visible error is produced (and remove the redundant earlier ext.rgApiV2 stub in this test).

Copilot uses AI. Check for mistakes.
Comment on lines +305 to +313
const tryFindRevealedResource = async (): Promise<TreeElement | undefined> => {
const revealedId = await ext.rgApiV2.resources.getSelectedAzureNode();
if (revealedId) {
const strippedId = removeAzureTenantPrefix(revealedId);
return await branchDataProvider.findNodeById(strippedId);
}

return await branchDataProvider.findNodeById(fulId);
};
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tryFindRevealedResource closes over branchDataProvider, which is declared later in the function. It’s currently safe due to the call order, but it’s easy to break via refactor and can be confusing with block-scoped TDZ rules. Consider moving the branchDataProvider declaration above tryFindRevealedResource to keep variable initialization close to its use.

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +15
suite('vscodeUriHandler - Open in VS Code', () => {
test('prompts to sign in when subscription is not found and retries reveal', async () => {
const originalExecuteCommand = vscode.commands.executeCommand;

let revealCallCount = 0;
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests mutate global extension state (ext.rgApiV2, ext.cosmosDBBranchDataProvider, etc.) but only restore vscode.commands.executeCommand. That can leak stubs into other test suites and cause order-dependent failures. Please capture the original ext.* values and restore them in afterEach/finally (or use a helper) so each test leaves the global ext state unchanged.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] : [Open in VSCode] from Azure portal should handle tenant switch gracefully!

2 participants