Skip to content

Conversation

@parameja1
Copy link
Contributor

@parameja1 parameja1 commented Jul 2, 2025

Problem

With updating Toolkit version to latest in SMUS CodeEditor Spaces, observing Toolkit throws an error as attached in screenshot below with error message

Attempted to get compute region without initializing
image

Solution

  • Issue is due to getComputeRegion() invoked first before compute region is initialized
  • hence solution is to Make isCn() resilient to uninitialized state and return a default value
  • Tested with a local debug artifact in SMUS CodeEditor space, toolkit activation completed and working
image
  • Also Tested the changes in standalone VS code application and SMAI compute instance, and toolkit explorer view is seen working as expected

image

image

  • Also tested the vsix in china region cn-north-1, and working as expected
image
  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@parameja1 parameja1 requested a review from a team as a code owner July 2, 2025 22:41
@github-actions
Copy link

github-actions bot commented Jul 2, 2025

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.
  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

return getComputeRegion()?.startsWith('cn') ?? false
} catch (e) {
// If compute region isn't initialized yet, assume we're not in a CN region
getLogger().debug('isCn called before compute region initialized, defaulting to false')
Copy link
Contributor

Choose a reason for hiding this comment

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

should we also log the error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review, added error logging as well as unit tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

2 of the CI workflow checks are failing seemingly due to a change merged recently and not due to this commit, reference: https://github.com/aws/aws-toolkit-vscode/actions/runs/16175639516/job/45659998532

Comment on lines 184 to 187
// Restore original getComputeRegion if it was stubbed
if (utils.getComputeRegion.restore) {
utils.getComputeRegion.restore()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this? I see sandbox.restore() is called in our afterEach, doesn't this already reset all stubs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, not needed necessarily. Added it initially for best practice, but since sandbox is restored in afterEach, underlying stubs should also get cleaned

Comment on lines +204 to +207
} catch (err) {
getLogger().error(`Error in isCn method: ${err}`)
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we instead be throwing the error here? We already handle the known case above by returning false when the region is uninitialized, but this can catch other errors that I'm not sure we should assume returning false for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, the case that throws error is handled already, and i didnt find any error cases that could result from the getComputeRegion method, hence it looks safe to not throw error back

@laileni-aws laileni-aws enabled auto-merge (squash) July 11, 2025 20:49
@laileni-aws
Copy link
Contributor

/retryBuilds

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.

4 participants