PowerShell / PowerShell/PowerShell

Import-Clixml ignores -ErrorAction parameter

Abierto
#27,641 3 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Needs-Triage
Lenguaje dominante
C#
Estrellas
55.5k
Forks
8.5k
Merge medio
1 d 2 h
PR fusionados (30 d)
88

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza reproduciendo el comando Import-Clixml con una ruta inexistente y -ErrorAction SilentlyContinue; después, sigue la ruta de apertura del archivo y de manejo de errores del comando. Se considera completado cuando el comando no produce ninguna salida ni excepción en este caso, y conserva el comportamiento indicado para los errores habituales de Import-Clixml.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
csharp, powershell
Área
cli
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
55/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.