Skip to content

Commit 3eeef3e

Browse files
authored
Remove Error Recording of Nonterminating Errors (#22965)
* Remove Error Recording of Nonterminating Errors * Fix Test Case * Suppress Unexpected Outputs * Address review comments
1 parent f649e7a commit 3eeef3e

9 files changed

+46
-46
lines changed

tools/Az.Tools.Installer/exports/Install-AzModule.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ function Install-AzModule {
8888
try {
8989
$Invoker = $MyInvocation.MyCommand
9090
if ($PSCmdlet.ParameterSetName -eq 'Default') {
91-
Install-AzModule_Default @PSBoundParameters -Invoker $Invoker -ErrorVariable +errorRecords
91+
Install-AzModule_Default @PSBoundParameters -Invoker $Invoker
9292
}
9393
else {
94-
Install-AzModule_ByPath @PSBoundParameters -Invoker $Invoker -ErrorVariable +errorRecords
94+
Install-AzModule_ByPath @PSBoundParameters -Invoker $Invoker
9595
}
9696
$IsSuccess = $true
9797
}

tools/Az.Tools.Installer/exports/Uninstall-AzModule.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function Uninstall-AzModule {
6868
try {
6969
if ($RemoveAzureRm -and ($Force -or $PSCmdlet.ShouldProcess('Remove AzureRm modules', 'AzureRm modules', 'Remove'))) {
7070
Write-Progress -Id $script:FixProgressBarId "Uninstall Azure and AzureRM."
71-
Remove-AzureRM -ErrorVariable +errorRecords
71+
Remove-AzureRM
7272
}
7373

7474
if ($Force -or $PSCmdlet.ShouldProcess('Remove Az if installed', 'Az', 'Remove')) {
@@ -78,7 +78,7 @@ function Uninstall-AzModule {
7878
Write-Progress -Id $script:FixProgressBarId "Check currently installed Az modules."
7979

8080
$allInstalled = @()
81-
$allInstalled += Get-AllAzModule -PrereleaseOnly:$PrereleaseOnly -ErrorVariable +errorRecords
81+
$allInstalled += Get-AllAzModule -PrereleaseOnly:$PrereleaseOnly
8282

8383
$moduleToUninstall = $allInstalled | Foreach-Object {[PSCustomObject]@{Name = $_.Name; Version = $_.Version}}
8484
if ($Name) {
@@ -91,7 +91,7 @@ function Uninstall-AzModule {
9191
}
9292
else {
9393
if ($ExcludeModule) {
94-
$ExcludeModule = Normalize-ModuleName $ExcludeModule -ErrorVariable +errorRecords
94+
$ExcludeModule = Normalize-ModuleName $ExcludeModule
9595
$moduleToUninstall = $moduleToUninstall | Where-Object {$ExcludeModule -NotContains $_.Name}
9696
$modulesNotInstalled = $ExcludeModule | Where-Object {!$allInstalled -or $allInstalled.Name -NotContains $_}
9797
if ($modulesNotInstalled) {
@@ -129,11 +129,11 @@ function Uninstall-AzModule {
129129
}
130130
}
131131
foreach ($versionString in $versionStrings) {
132-
PowerShellGet\Uninstall-Module -Name $moduleName -RequiredVersion $versionString -AllowPrerelease -ErrorAction 'Continue' -ErrorVariable +errorRecords
132+
PowerShellGet\Uninstall-Module -Name $moduleName -RequiredVersion $versionString -AllowPrerelease -ErrorAction 'Continue'
133133
}
134134
}
135135
else {
136-
PowerShellGet\Uninstall-Module -Name $moduleName -AllVersion -AllowPrerelease -ErrorAction 'Continue' -ErrorVariable +errorRecords
136+
PowerShellGet\Uninstall-Module -Name $moduleName -AllVersion -AllowPrerelease -ErrorAction 'Continue'
137137
}
138138
Write-Debug "[$Invoker] Uninstalling $moduleName version $versions is completed."
139139
$index += 1

tools/Az.Tools.Installer/exports/Update-AzModule.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ function Update-AzModule {
6262
try {
6363
Write-Progress -Id $script:FixProgressBarId "Check currently installed Az modules."
6464

65-
$Name = Normalize-ModuleName $Name -ErrorVariable +errorRecords
66-
$allInstalled = Get-AllAzModule -ErrorVariable +errorRecords
65+
$Name = Normalize-ModuleName $Name
66+
$allInstalled = Get-AllAzModule
6767
if (!$allInstalled) {
6868
Write-Warning "[$Invoker] No Az modules are installled."
6969
$IsSuccess = $true
@@ -75,7 +75,7 @@ function Update-AzModule {
7575
$intersection = $intersection | Where-Object {$_.Name -eq "Az.Accounts" -or $Name -Contains $_.Name}
7676
$modulesNotInstalled = $Name | Where-Object {$allInstalled.Name -NotContains $_}
7777
if ($modulesNotInstalled) {
78-
Write-Error "[$Invoker] $modulesNotInstalled are not installed. Please firstly install them before update." -ErrorVariable +errorRecords
78+
Write-Error "[$Invoker] $modulesNotInstalled are not installed. Please firstly install them before update."
7979
#If Az.Accounts is in modulesNotInstalled,it will be warned but installed anyway.
8080
}
8181
}
@@ -94,7 +94,7 @@ function Update-AzModule {
9494
if ($Repository) {
9595
$findModuleParams.Add('Repository', $Repository)
9696
}
97-
$modulesToUpdate = Get-AzModuleFromRemote @findModuleParams -ErrorVariable +errorRecords
97+
$modulesToUpdate = Get-AzModuleFromRemote @findModuleParams
9898
if ($modulesToUpdate) {
9999
$Repository = $modulesToUpdate.Repository | Select-Object -First 1
100100
}
@@ -147,7 +147,7 @@ function Update-AzModule {
147147
Force = $Force
148148
Invoker = $Invoker
149149
}
150-
$output = Install-AzModuleInternal @installModuleParams -ErrorVariable +errorRecords
150+
$output = Install-AzModuleInternal @installModuleParams
151151

152152
if ($output) {
153153
$moduleUpdated = $moduleUpdateTable | Where-Object {$output.Name.Contains($_.Name)}

tools/Az.Tools.Installer/internal/Install-AzModuleInternal.ps1

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ function Install-AzModuleInternal {
6060
[string]$tempRepo = Join-Path ([Path]::GetTempPath()) ((New-Guid).Guid)
6161
#$tempRepo = Join-Path 'D:/PSLocalRepo/' (Get-Date -Format "yyyyddMM-HHmm")
6262
if (Test-Path -Path $tempRepo) {
63-
Microsoft.PowerShell.Management\Remove-Item -Path $tempRepo -Recurse -WhatIf:$false -ErrorVariable errorRecords
63+
Microsoft.PowerShell.Management\Remove-Item -Path $tempRepo -Recurse -WhatIf:$false
6464
}
65-
$null = Microsoft.PowerShell.Management\New-Item -ItemType Directory -Path $tempRepo -WhatIf:$false -ErrorVariable errorRecords
65+
$null = Microsoft.PowerShell.Management\New-Item -ItemType Directory -Path $tempRepo -WhatIf:$false
6666
Write-Debug "[$Invoker] The repository folder $tempRepo is created."
6767

68-
PowerShellGet\Unregister-PSRepository -Name $script:AzTempRepoName -ErrorAction 'SilentlyContinue'
69-
PowerShellGet\Register-PSRepository -Name $script:AzTempRepoName -SourceLocation $tempRepo -ErrorAction 'Stop' -ErrorVariable errorRecords
70-
PowerShellGet\Set-PSRepository -Name $script:AzTempRepoName -InstallationPolicy Trusted -ErrorVariable errorRecords
68+
$null = PowerShellGet\Unregister-PSRepository -Name $script:AzTempRepoName -ErrorAction 'SilentlyContinue'
69+
$null = PowerShellGet\Register-PSRepository -Name $script:AzTempRepoName -SourceLocation $tempRepo -ErrorAction 'Stop' -ErrorVariable +errorRecords
70+
PowerShellGet\Set-PSRepository -Name $script:AzTempRepoName -InstallationPolicy Trusted
7171
Write-Debug "[$Invoker] The temporary repository $script:AzTempRepoName is registered."
7272

7373
$InstallStarted = Get-Date
@@ -126,7 +126,7 @@ function Install-AzModuleInternal {
126126
if ($confirmUninstallation) {
127127
PowerShellGet\Uninstall-Module -Name "Az.Accounts" -AllVersion -AllowPrerelease -ErrorAction 'SilentlyContinue'
128128
}
129-
PowerShellGet\Install-Module @installModuleParams -Name "Az.Accounts" -RequiredVersion "$($modules[0].Version)" -ErrorVariable +errorRecords
129+
PowerShellGet\Install-Module @installModuleParams -Name "Az.Accounts" -RequiredVersion "$($modules[0].Version)"
130130
}
131131
$moduleInstalled += [PSCustomObject]@{
132132
Name = "Az.Accounts"
@@ -173,7 +173,7 @@ function Install-AzModuleInternal {
173173
if ($RemovePrevious) {
174174
PowerShellGet\Uninstall-Module -Name $moduleName -AllVersion -AllowPrerelease -ErrorAction 'SilentlyContinue'
175175
}
176-
PowerShellGet\Install-Module @installModuleParam -Name $moduleName -RequiredVersion "$moduleVersion" -ErrorVariable +errorRecords
176+
PowerShellGet\Install-Module @installModuleParam -Name $moduleName -RequiredVersion "$moduleVersion"
177177
$state = "succeeded"
178178
}
179179
catch {
@@ -205,9 +205,9 @@ function Install-AzModuleInternal {
205205
$jobs += Start-ThreadJob -Name "Az.Tools.Installer" -InitializationScript $functions -ScriptBlock {
206206
$tmodule = $using:module
207207
$tInstallModuleParam = $using:installModuleParams
208-
$result = Install-SingleModule -ModuleName $tmodule.Name -ModuleVersion $tmodule.Version -InstallModuleParam $tInstallModuleParam -RemovePrevious:($using:confirmUninstallation) -ErrorVariable +errorRecords
208+
$result = Install-SingleModule -ModuleName $tmodule.Name -ModuleVersion $tmodule.Version -InstallModuleParam $tInstallModuleParam -RemovePrevious:($using:confirmUninstallation)
209209
Write-Output $result
210-
} -ThrottleLimit $maxJobCount -ErrorVariable +errorRecords
210+
} -ThrottleLimit $maxJobCount
211211
}
212212
}
213213
else {
@@ -230,7 +230,7 @@ function Install-AzModuleInternal {
230230
$jobs += Start-Job -Name "Az.Tools.Installer" -InitializationScript $functions -ScriptBlock {
231231
$tmodule = $using:module
232232
$tInstallModuleParam = $using:installModuleParams
233-
$result = Install-SingleModule -ModuleName $tmodule.Name -ModuleVersion $tmodule.Version -InstallModuleParam $tInstallModuleParam -RemovePrevious:($using:confirmUninstallation) -ErrorVariable +errorRecords
233+
$result = Install-SingleModule -ModuleName $tmodule.Name -ModuleVersion $tmodule.Version -InstallModuleParam $tInstallModuleParam -RemovePrevious:($using:confirmUninstallation)
234234
Write-Output $result
235235
}
236236
Write-Progress -ParentId $script:FixProgressBarId -Activity "Install Module" -Status "$($module.Name) version $($module.Version)" -PercentComplete ($index / $modules.Count * 100)
@@ -255,9 +255,9 @@ function Install-AzModuleInternal {
255255
}
256256
}
257257
else {
258-
Write-Error "[$Invoker] Installing $($result.ModuleName) of version $($result.ModuleVersion) is failed. `n$($result.Error)" -ErrorVariable +errorRecords
258+
Write-Error "[$Invoker] Installing $($result.ModuleName) of version $($result.ModuleVersion) is failed. `n$($result.Error)"
259259
}
260-
Remove-Job $job -Confirm:$false -ErrorVariable +errorRecords
260+
Remove-Job $job -Confirm:$false
261261
if ($PSVersionTable.PSEdition -eq "Core") {
262262
Write-Progress -ParentId $script:FixProgressBarId -Activity "Install Module" -Status "$($result.ModuleName) of version $($result.ModuleVersion)" -PercentComplete ($index / $jobs.Count * 100)
263263
$index += 1
@@ -271,7 +271,7 @@ function Install-AzModuleInternal {
271271
$jobs = Get-Job -Name "Az.Tools.Installer" -ErrorAction 'SilentlyContinue'
272272
if ($jobs) {
273273
Stop-Job $jobs
274-
Remove-Job $jobs -Confirm:$false -ErrorVariable +errorRecords
274+
Remove-Job $jobs -Confirm:$false
275275
}
276276
}
277277

@@ -282,11 +282,11 @@ function Install-AzModuleInternal {
282282
if ($Force -or !$WhatIfPreference) {
283283
if (!$DontClean) {
284284
Write-Debug "[$Invoker] The temporary repository $script:AzTempRepoName is unregistered."
285-
PowerShellGet\Unregister-PSRepository -Name $script:AzTempRepoName -ErrorAction 'Continue' -ErrorVariable +errorRecords
285+
$null = PowerShellGet\Unregister-PSRepository -Name $script:AzTempRepoName -ErrorAction 'Continue'
286286

287287
Write-Debug "[$Invoker] The Repository folder $tempRepo is removed."
288288
if (Test-Path -Path $tempRepo) {
289-
Microsoft.PowerShell.Management\Remove-Item -Path $tempRepo -Recurse -WhatIf:$false -ErrorVariable +errorRecords
289+
Microsoft.PowerShell.Management\Remove-Item -Path $tempRepo -Recurse -WhatIf:$false
290290
}
291291
}
292292
}

tools/Az.Tools.Installer/internal/Install-AzModule_ByPath.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function Install-AzModule_ByPath {
5151
process {
5252
if ($RemoveAzureRm -and ($Force -or $PSCmdlet.ShouldProcess('Remove AzureRm modules', 'AzureRm modules', 'Remove'))) {
5353
Write-Progress -Id $script:FixProgressBarId "Uninstall Azure and AzureRM."
54-
Remove-AzureRM -ErrorVariable +errorRecords
54+
Remove-AzureRM
5555
}
5656

5757
if ($Force -or $PSCmdlet.ShouldProcess('Remove Az if installed', 'Az', 'Remove')) {
@@ -65,14 +65,14 @@ function Install-AzModule_ByPath {
6565
[string]$tempRepo = Join-Path ([Path]::GetTempPath()) ((New-Guid).Guid)
6666
#$tempRepo = Join-Path 'D:/PSLocalRepo/' (Get-Date -Format "yyyyddMM-HHmm")
6767
if (Test-Path -Path $tempRepo) {
68-
Microsoft.PowerShell.Management\Remove-Item -Path $tempRepo -Recurse -WhatIf:$false -ErrorVariable +errorRecords
68+
Microsoft.PowerShell.Management\Remove-Item -Path $tempRepo -Recurse -WhatIf:$false
6969
}
70-
$null = Microsoft.PowerShell.Management\New-Item -ItemType Directory -Path $tempRepo -WhatIf:$false -ErrorVariable +errorRecords
70+
$null = Microsoft.PowerShell.Management\New-Item -ItemType Directory -Path $tempRepo -WhatIf:$false
7171
Write-Debug "[$Invoker] The repository folder $tempRepo is created."
7272

73-
PowerShellGet\Unregister-PSRepository -Name $script:AzTempRepoName -ErrorAction 'SilentlyContinue'
74-
PowerShellGet\Register-PSRepository -Name $script:AzTempRepoName -SourceLocation $tempRepo -ErrorAction 'Stop' -ErrorVariable +errorRecords
75-
PowerShellGet\Set-PSRepository -Name $script:AzTempRepoName -InstallationPolicy Trusted -ErrorVariable +errorRecords
73+
$null = PowerShellGet\Unregister-PSRepository -Name $script:AzTempRepoName -ErrorAction 'SilentlyContinue'
74+
$null = PowerShellGet\Register-PSRepository -Name $script:AzTempRepoName -SourceLocation $tempRepo -ErrorAction 'Stop' -ErrorVariable +errorRecords
75+
PowerShellGet\Set-PSRepository -Name $script:AzTempRepoName -InstallationPolicy Trusted
7676
Write-Debug "[$Invoker] The temporary repository $script:AzTempRepoName is registered."
7777

7878
$installModuleParams = @{
@@ -83,18 +83,18 @@ function Install-AzModule_ByPath {
8383
Force = $Force
8484
Invoker = $Invoker
8585
}
86-
Install-SingleModuleFromPackage @installModuleParams -ErrorVariable +errorRecords
86+
Install-SingleModuleFromPackage @installModuleParams
8787
}
8888
}
8989
finally {
9090
if ($Force -or !$WhatIfPreference) {
9191
if (!$DontClean) {
9292
Write-Debug "[$Invoker] The temporary repository $script:AzTempRepoName is unregistered."
93-
PowerShellGet\Unregister-PSRepository -Name $script:AzTempRepoName -ErrorAction 'Continue' -ErrorVariable +errorRecords
93+
$null = PowerShellGet\Unregister-PSRepository -Name $script:AzTempRepoName -ErrorAction 'Continue'
9494

9595
Write-Debug "[$Invoker] The Repository folder $tempRepo is removed."
9696
if (Test-Path -Path $tempRepo) {
97-
Microsoft.PowerShell.Management\Remove-Item -Path $tempRepo -Recurse -WhatIf:$false -ErrorVariable +errorRecords
97+
Microsoft.PowerShell.Management\Remove-Item -Path $tempRepo -Recurse -WhatIf:$false
9898
}
9999
}
100100
}

tools/Az.Tools.Installer/internal/Install-AzModule_Default.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function Install-AzModule_Default {
6464
process {
6565
Write-Progress -Id $script:FixProgressBarId "Find modules on $Repository."
6666

67-
$Name = Normalize-ModuleName $Name -ErrorVariable +errorRecords
67+
$Name = Normalize-ModuleName $Name
6868
$findModuleParams = @{
6969
Name = $Name
7070
AllowPrerelease = $AllowPrerelease
@@ -79,7 +79,7 @@ function Install-AzModule_Default {
7979
}
8080

8181
$modules = @()
82-
$modules += Get-AzModuleFromRemote @findModuleParams -ErrorVariable +errorRecords | Sort-Object -Property Name
82+
$modules += Get-AzModuleFromRemote @findModuleParams | Sort-Object -Property Name
8383
if ($modules) {
8484
$Repository = $modules.Repository | Select-Object -First 1
8585
}
@@ -89,13 +89,13 @@ function Install-AzModule_Default {
8989
if ($moduleExcluded) {
9090
$azVersion = if ($RequiredAzVersion) {$RequiredAzVersion} else {"Latest"}
9191
$Repository = if ($Repository) {$Repository} else {'the registered repositories'}
92-
Write-Error "[$Invoker] The following specified modules:$moduleExcluded cannot be found in $Repository with the $azVersion version." -ErrorVariable +errorRecords
92+
Write-Error "[$Invoker] The following specified modules:$moduleExcluded cannot be found in $Repository with the $azVersion version."
9393
}
9494
}
9595

9696
if ($RemoveAzureRm -and ($Force -or $PSCmdlet.ShouldProcess('Remove AzureRm modules', 'AzureRm modules', 'Remove'))) {
9797
Write-Progress -Id $script:FixProgressBarId "Uninstall Azure and AzureRM."
98-
Remove-AzureRM -ErrorVariable +errorRecords
98+
Remove-AzureRM
9999
}
100100

101101
if ($Force -or $PSCmdlet.ShouldProcess('Remove Az if installed', 'Az', 'Remove')) {
@@ -118,7 +118,7 @@ function Install-AzModule_Default {
118118
Force = $Force
119119
Invoker = $Invoker
120120
}
121-
$output = Install-AzModuleInternal @installModuleParams -ErrorVariable +errorRecords
121+
$output = Install-AzModuleInternal @installModuleParams
122122

123123
if (!$WhatIfPreference -and $output) {
124124
Write-Output $output

tools/Az.Tools.Installer/internal/Install-SingleModuleFromPackage.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function Install-SingleModuleFromPackage{
8484
if ($confirmUninstallation) {
8585
PowerShellGet\Uninstall-Module -Name $moduleName -AllVersion -AllowPrerelease -ErrorAction 'SilentlyContinue'
8686
}
87-
PowerShellGet\Install-Module @installModuleParams -Name $moduleName -RequiredVersion "$moduleVersion" -ErrorVariable +errorRecords
87+
PowerShellGet\Install-Module @installModuleParams -Name $moduleName -RequiredVersion "$moduleVersion"
8888
}
8989

9090
if (!$WhatIfPreference) {

0 commit comments

Comments
 (0)