Skip to content

Conversation

d-s-dc
Copy link
Contributor

@d-s-dc d-s-dc commented Jul 28, 2025

Fixes #4594

Added a nullish coalescing operator to take care of the case when the returned value is null or undefined. Changing the getLatestVersionRange to throw error didn't make sense as it is just for trying to get the latest version. It's fine if the latest version cannot be retreived and the function returns null.

@d-s-dc d-s-dc requested a review from a team as a code owner July 28, 2025 23:44
Copy link
Member

@nturinski nturinski left a comment

Choose a reason for hiding this comment

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

This is a solid fix for issue #4594! The nullish coalescing operator appropriately handles the case where getLatestVersionRange() returns null/undefined, ensuring that extension bundles always get a valid version in host.json.

The change is minimal, targeted, and preserves the existing error handling while adding the necessary null safety. This should resolve the Python timer trigger project creation issue.

One minor consideration is whether the function signature should be updated to reflect that it can return null/undefined, but the fix itself is correct and ready for merge.

@@ -90,7 +90,7 @@ export namespace bundleFeedUtils {
export async function addDefaultBundle(context: IActionContext, hostJson: IHostJsonV2): Promise<void> {
let versionRange: string;
try {
versionRange = await getLatestVersionRange(context);
versionRange = (await getLatestVersionRange(context)) ?? defaultVersionRange;
Copy link
Member

Choose a reason for hiding this comment

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

Good fix for null/undefined handling! This change correctly addresses the issue described in #4594 where getLatestVersionRange() can return null or undefined, causing the extension bundle version to be missing from host.json.

The nullish coalescing operator (??) is the right solution here because:

  1. It handles both null and undefined return values from getLatestVersionRange()
  2. It falls back to defaultVersionRange which ensures the extension bundle gets a valid version
  3. It's more precise than the existing try/catch block since it only handles the null/undefined case, not all possible errors

This should fix the Python timer trigger project creation issue where host.json was missing the version property in extensionBundle.

Review generated with Copilot

@nturinski nturinski merged commit 009e964 into microsoft:main Jul 29, 2025
2 checks passed
@nturinski
Copy link
Member

Thanks for your contribution! This will be in our next release ❤️

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.

The host.json of python timer trigger project does not contain version of extension bundle
2 participants