vscode uri handler now asks for signing in to another account instead…#2899
vscode uri handler now asks for signing in to another account instead…#2899
Conversation
… of showing a "subscription not found" error. fixes #2686
|
I have not tested this yet, but we should not forget to add tenantId param to the Azure Portal, that's an essential part. |
There was a problem hiding this comment.
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.
| // 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'); | ||
| }, |
There was a problem hiding this comment.
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).
| 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); | ||
| }; |
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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.
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:
revealAzureResourceInExplorerinsrc/vscodeUriHandler.tsto 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]promptToFixAzureAccountAccessandrevealAzureResourceWithAccountPromptto encapsulate user prompting and retry logic for account/subscription issues.globalUriHandlerto properly propagateUserCancelledErrorand provide more descriptive failure messages.Localization and messaging updates:
l10n/bundle.l10n.jsonto 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:
test/vscodeUriHandler.test.tsto verify that the handler correctly prompts users and retries when encountering subscription/account issues, and that cancellation is handled as expected.Other changes:
globalUriHandlerfromextension.bundle.tsto make it available for testing and integration.parseErrorinsrc/vscodeUriHandler.ts.… of showing a "subscription not found" error.fixes #2686