Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-Date -UFormat '' throws an unhelpful exception for an empty string argument #5047

Closed
HumanEquivalentUnit opened this issue Oct 7, 2017 · 3 comments · Fixed by #5055
Closed
Labels
Hacktoberfest Potential candidate to participate in Hacktoberfest Resolution-Fixed The issue is fixed. Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module

Comments

@HumanEquivalentUnit
Copy link
Contributor

An empty string argument in Get-Date -UFormat '' throws IndexOutOfRangeException, it would be more helpful if the error said what was wrong and directed attention to the UFormat argument. "Missing or Invalid UFormat String" or words to that effect.

Steps to reproduce

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

Expected behavior

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

Actual behavior

A message about some internal problem.

Environment data

> $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
@SteveL-MSFT SteveL-MSFT added WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module Hacktoberfest Potential candidate to participate in Hacktoberfest Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors labels Oct 7, 2017
@SteveL-MSFT
Copy link
Member

Agree, all error messages should be actionable by the user (or informative if not possible)

@djweber
Copy link

djweber commented Oct 7, 2017

I'll work on this one.

@iSazonov
Copy link
Collaborator

iSazonov commented Oct 7, 2017

@DDWR Thanks for grab this. Typically, beginners receive most style comments. Please read out Coding Guidelines. Mainly you should follow the style of the surrounding code. Also please add a test (use our ShouldBeErrorId function). Put new error message in appropriate Resx file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest Potential candidate to participate in Hacktoberfest Resolution-Fixed The issue is fixed. Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants