| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Steve Lee (@SteveL-MSFT) If the new test uses $error[0]: It "Should write non-terminating error if argument is a folder" {
$result = $pshome, "${pshome}\pwsh.dll" | Get-FileHash
$result.Count | Should -Be 1
$error[0].FullyQualifiedErrorId | Should -BeExactly "UnauthorizedAccessError,Microsoft.PowerShell.Commands.GetFileHashCommand"
}it unexpectedly fail with an ConciseView error MethodInvocationException:
Line |
127 | $remainingMessage = $remainingMessage.Substring($substring.Length - $prefix.Length).Trim()
| ^ Exception calling "Substring" with "1" argument(s): "StartIndex cannot be less than zero. (Parameter 'startIndex')"I cannot find simple repo steps. |
Sorry, something went wrong.
…Hash.cs Co-Authored-By: Joel Sallow (/u/ta11ow) <32407840+vexx32@users.noreply.github.com>
…Hash.cs Co-Authored-By: Joel Sallow (/u/ta11ow) <32407840+vexx32@users.noreply.github.com>
| catch (FileNotFoundException ex) | ||
| { | ||
| ErrorRecord errorRecord = new ErrorRecord(ex, | ||
| var errorRecord = new ErrorRecord( | ||
| ex, | ||
| "FileNotFound", | ||
| ErrorCategory.ObjectNotFound, | ||
| path); | ||
| WriteError(errorRecord); | ||
| } | ||
| catch (UnauthorizedAccessException ex) | ||
| { | ||
| var errorRecord = new ErrorRecord( | ||
| ex, | ||
| "UnauthorizedAccessError", | ||
| ErrorCategory.InvalidData, | ||
| path); | ||
| WriteError(errorRecord); | ||
| } |
There was a problem hiding this comment.
Do you think it's worth doing a general catch or additional catches here as well? Looking at the exceptions that can be thrown from System.IO.File.OpenRead it seems likely we can run into the following exceptions somewhat commonly as well:
Sorry, something went wrong.
There was a problem hiding this comment.
IOException combines FileNotFoundException, DirectoryNotFoundException, and PathTooLongException.
I guess PathTooLongException will be raised above at path resolving time.
So nothing to do. :-)
Sorry, something went wrong.
|
🎉v7.0.0-rc.2 has been released which incorporates this pull request.:tada: Handy links: |
Sorry, something went wrong.
|
It would be appreciated if this error could be changed from "Access Denied" to something more specific, i.e.: "SKIPPED: Invalid path: folder" or something. I'm trying to recurse through my photo archive to try to find duplicates. For each file, I send FullName to get-filehash. I get a LOT of these errors, which implies a permissions issues, but after finding this pull request, I see that it is working as expected. Invocation: |
Sorry, something went wrong.
|
You can add the -File param to your Get-ChildItem call to avoid the issue entirely. But yeah, that's a fair call. Would be a good idea to open a new issue for that. 🙂 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR Summary
Fix #11110
If Get-FileHash gets a folder as argument we should write non-terminate error.
PR Context
PR Checklist