PowerShell / PowerShell/PowerShell
Import-Clixml ignores -ErrorAction parameter
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 55.5k
- Fork
- 8.5k
- Merge medio
- 1g 2h
- PR unite (30g)
- 88
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo il comando Import-Clixml con un percorso inesistente e -ErrorAction SilentlyContinue, quindi traccia il percorso di apertura del file e di gestione degli errori del comando. Il lavoro è completato quando, in questo caso, il comando non produce alcun output né eccezione, preservando al contempo il comportamento riportato per gli errori ordinari di Import-Clixml.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp, powershell
- Ambito
- cli
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 55/100