Skip to content
Merged
Changes from 3 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
11 changes: 5 additions & 6 deletions src/Functions/Functions.Autorest/custom/HelperFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,14 @@ function GetEndpointSuffix
[Microsoft.Azure.PowerShell.Cmdlets.Functions.DoNotExportAttribute()]
param()

$environmentName = (Get-AzContext).Environment.Name
$storageEndpointSuffix = (Get-AzContext).Environment.StorageEndpointSuffix

Comment on lines +163 to 164
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

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

The function could throw a null reference exception if Get-AzContext returns null. Consider adding error handling to check if the context exists before accessing its properties. For example: '$context = Get-AzContext; if ($null -eq $context) { return '' }; $storageEndpointSuffix = $context.Environment.StorageEndpointSuffix'

Suggested change
$storageEndpointSuffix = (Get-AzContext).Environment.StorageEndpointSuffix
$context = Get-AzContext
if ($null -eq $context -or $null -eq $context.Environment)
{
return ''
}
$storageEndpointSuffix = $context.Environment.StorageEndpointSuffix

Copilot uses AI. Check for mistakes.
switch ($environmentName)
if ([string]::IsNullOrWhiteSpace($storageEndpointSuffix))
{
"AzureUSGovernment" { ';EndpointSuffix=core.usgovcloudapi.net' }
"AzureChinaCloud" { ';EndpointSuffix=core.chinacloudapi.cn' }
"AzureCloud" { ';EndpointSuffix=core.windows.net' }
default { '' }
return ''
}

return ";EndpointSuffix=$storageEndpointSuffix"
}

function NewAppSetting
Expand Down
Loading