PowerShell / PowerShell/PowerShell
Import-Clixml ignores -ErrorAction parameter
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 55.5k
- Forks
- 8.5k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 88
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Import-Clixml should not raise an exception when called with -ErrorAction SilentlyContinue. But it does.
Steps to repro:
Open a terminal and provide the path to a non-existing file:
Import-Clixml -Path .\there-is-no-spoon -ErrorAction SilentlyContinue
It should produce no output, but you will get the exception
Expected behavior
> Import-Clixml -Path .\there-is-no-spoon -ErrorAction SilentlyContinue
PS >
Actual behavior
> Import-Clixml -Path .\there-is-no-spoon -ErrorAction SilentlyContinue
PS> Import-Clixml: Could not find file 'C:\Windows\there-is-no-spoon'.
Error details
PS C:\Windows> get-error
Exception :
Type : System.IO.FileNotFoundException
Message : Could not find file 'C:\Windows\there-is-no-spoon'.
FileName : C:\Windows\there-is-no-spoon
TargetSite :
Name : CreateFile
DeclaringType : [Microsoft.Win32.SafeHandles.SafeFileHandle]
MemberType : Method
Module : System.Private.CoreLib.dll
Source : System.Private.CoreLib
HResult : -2147024894
StackTrace :
at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access,
FileShare share, FileOptions options)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare
share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share,
FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access,
FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.Management.Automation.PathUtils.OpenFileStream(String filePath, PSCmdlet command, Boolean isLiteralPath)
CategoryInfo : OpenError: (:) [Import-Clixml], FileNotFoundException
FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ImportClixmlCommand
InvocationInfo :
MyCommand : Import-Clixml
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 9
Line : Import-Clixml -Path .\there-is-no-spoon -ErrorAction SilentlyContinue
Statement : Import-Clixml -Path .\there-is-no-spoon -ErrorAction SilentlyContinue
PositionMessage : At line:1 char:1
+ Import-Clixml -Path .\there-is-no-spoon -ErrorAction SilentlyContinue
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : Import-Clixml
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
Environment data
PS C:\Users\adima\TMD_Files\Debug> $PSVersionTable
Name Value
---- -----
PSVersion 7.6.3
PSEdition Core
GitCommitId 7.6.3
OS Microsoft Windows 10.0.26200
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.4
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Import-Clixml command with a nonexistent path and -ErrorAction SilentlyContinue, then trace the command's file-opening and error-handling path. Done means the command produces no output or exception for this case while preserving the reported behavior for ordinary Import-Clixml failures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100