Skip to content

Commit

Permalink
silence exception when testing some invalid paths in pwsh 7 (fix #96)
Browse files Browse the repository at this point in the history
  • Loading branch information
jantari committed Sep 26, 2023
1 parent c60f5f2 commit 5db48ae
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion private/Split-ExecutableAndArguments.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@
)
}

$testPathRelative = Join-Path -Path $WorkingDirectory -ChildPath $testPath
# In PowerShell 7.3 and 7.4 Join-Path throws an exception (not a PowerShell error, a .NET exception)
# when it tries to combine certain invalid paths (e.g. Join-Path -Path 'C:\' -ChildPath 'C:\ /x:').
# These exceptions are not influenced by ErrorAction, so we need a try-catch. We still set ErrorAction
# to Stop because whenever Join-Path doesn't succeed for any reason, we can always skip and continue
# in the loop because there won't be a new path to test in testPathRelative. See issue #96.
try {
$testPathRelative = Join-Path -Path $WorkingDirectory -ChildPath $testPath -ErrorAction Stop
}
catch [System.IO.IOException] {
continue
}

if ( [System.IO.File]::Exists($testPathRelative) ) {
return @(
Expand Down

1 comment on commit 5db48ae

@github-actions
Copy link

Choose a reason for hiding this comment

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

PSScriptAnalyzer results as of this commit:

  • 2 Information
  • 8 Warning
See details
Location : ./public/Set-LSUClientConfiguration.ps1 [1, 10]
RuleName : PSUseShouldProcessForStateChangingFunctions
Severity : Warning
Message  : Function 'Set-LSUClientConfiguration' has verb that could change system state
           . Therefore, the function has to support 'ShouldProcess'.

Location : ./public/Install-LSUpdate.ps1 [152, 21]
RuleName : PSUseOutputTypeCorrectly
Severity : Information
Message  : The cmdlet 'Install-LSUpdate' returns an object of type 'PackageInstallResult
           ' but this type is not declared in the OutputType attribute.

Location : ./public/Install-LSUpdate.ps1 [189, 21]
RuleName : PSUseOutputTypeCorrectly
Severity : Information
Message  : The cmdlet 'Install-LSUpdate' returns an object of type 'PackageInstallResult
           ' but this type is not declared in the OutputType attribute.

Location : ./private/Split-ExecutableAndArguments.ps1 [1, 10]
RuleName : PSUseSingularNouns
Severity : Warning
Message  : The cmdlet 'Split-ExecutableAndArguments' uses a plural noun. A singular noun
            should be used instead.

Location : ./private/Debug-LongRunningProcess.ps1 [44, 13]
RuleName : PSAvoidUsingEmptyCatchBlock
Severity : Warning
Message  : Empty catch block is used. Please use Write-Error or throw statements in catc
           h blocks.

Location : ./private/Debug-LongRunningProcess.ps1 [139, 82]
RuleName : PSReviewUnusedParameter
Severity : Warning
Message  : The parameter 'lParam' has been declared but not used. 

Location : ./private/Compare-Array.ps1 [30, 17]
RuleName : PSReviewUnusedParameter
Severity : Warning
Message  : The parameter 'in' has been declared but not used. 

Location : ./private/Resolve-XMLDependencies.ps1 [1, 10]
RuleName : PSUseSingularNouns
Severity : Warning
Message  : The cmdlet 'Resolve-XMLDependencies' uses a plural noun. A singular noun shou
           ld be used instead.

Location : ./private/Invoke-PackageCommand.ps1 [303, 29]
RuleName : PSAvoidUsingEmptyCatchBlock
Severity : Warning
Message  : Empty catch block is used. Please use Write-Error or throw statements in catc
           h blocks.

Location : ./private/Set-BIOSUpdateRegistryFlag.ps1 [1, 10]
RuleName : PSUseShouldProcessForStateChangingFunctions
Severity : Warning
Message  : Function 'Set-BIOSUpdateRegistryFlag' has verb that could change system state
           . Therefore, the function has to support 'ShouldProcess'.

Please sign in to comment.