PowerShell / PowerShell/PowerShell

Import-Clixml ignores -ErrorAction parameter

Open
#27,641 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Needs-Triage
Dominant language
C#
Stars
55.5k
Forks
8.5k
Avg merge
1d 2h
Merged PRs (30d)
88

Description

Prerequisites
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
Image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.