Powershell: Get-Date -UFormat '' arroja una excepción inútil para un argumento de cadena vacío

Creado en 7 oct. 2017  ·  3Comentarios  ·  Fuente: PowerShell/PowerShell

Un argumento de cadena vacía en Get-Date -UFormat '' arroja IndexOutOfRangeException , sería más útil si el error dijera qué estaba mal y dirigiera la atención al argumento UFormat. "Cadena UFormat faltante o no válida" o palabras similares.

pasos para reproducir

PS /test> get-date -uformat "$accidentallyEmptyFormatStringVariable"
get-date : Index was outside the bounds of the array.
At line:1 char:1
+ get-date -uformat ''
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-Date], IndexOutOfRangeException
    + FullyQualifiedErrorId : System.IndexOutOfRangeException,Microsoft.PowerShell.Commands.GetDateCommand

Comportamiento esperado

A message directing attention to the -UFormat string parameter being empty.

Comportamiento real

A message about some internal problem.

Datos del entorno

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-beta.8
PSEdition                      Core
GitCommitId                    v6.0.0-beta.8
OS                             Linux 2.6.32-042stab120.6 #1 SMP Thu Oct 27 16:59:03 MSK 2016
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Area-Cmdlets-Utility Hacktoberfest Resolution-Fixed Up-for-Grabs

Comentario más útil

Trabajaré en este.

Todos 3 comentarios

De acuerdo, todos los mensajes de error deben ser procesables por el usuario (o informativos si no es posible)

Trabajaré en este.

@DdWr Gracias por agarrar esto. Por lo general, los principiantes reciben la mayoría de los comentarios de estilo. Por favor, lea las Directrices de codificación . Principalmente, debe seguir el estilo del código circundante. También agregue una prueba (use nuestra función ShouldBeErrorId). Coloque un nuevo mensaje de error en el archivo Resx apropiado.

¿Fue útil esta página
0 / 5 - 0 calificaciones