Skip to content

Get-FormatData quietly ignores non-existing type-name arguments #4235

Closed

Description

Steps to reproduce

Get-FormatData NoSuch.Type.Exists.Or.IsLoaded

Expected behavior

An error that indicates that the type does not exist (in the current session).

Actual behavior

A quiet no-op. No output, $? reports $True.

Environment data

PowerShell Core v6.0.0-beta.3 on macOS 10.12.5
PowerShell Core v6.0.0-beta.3 on Ubuntu 16.04.1 LTS
PowerShell Core v6.0.0-beta.3 on Microsoft Windows 10 Pro (64-bit; v10.0.14393)
Windows PowerShell v5.1.15063.413 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)

Activity

  1. faraazahmad commented on Jul 27, 2018

    @faraazahmad
    Contributor

    I would like to work on this

  2. faraazahmad commented on Jul 28, 2018

    @faraazahmad
    Contributor

    Michael Klement (@mklement0) Steve Lee (@SteveL-MSFT) What should the ErrorCategory be?

  3. mklement0 commented on Jul 29, 2018

    @mklement0
    ContributorAuthor

    Syed Faraaz Ahmad (@faraazahmad):

    Thanks for your willingness to take this on.

    I'm not the best person to ask, but looking at the enumeration values at https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.errorcategory?view=powershellsdk-1.1.0, perhaps ResourceUnavailable?

  4. SteveL-MSFT commented on Jul 30, 2018

    @SteveL-MSFT
    Member

    Syed Faraaz Ahmad (@faraazahmad) consider it yours! Thanks!

  5. faraazahmad commented on Jul 31, 2018

    @faraazahmad
    Contributor

    So my code now outputs this:

    PS /home/faraaz> Get-FormatData yolo
    Get-FormatData : No such type
    At line:1 char:1
    + Get-FormatData yolo
    + ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (System.String[]:String[]) [Get-FormatData], Exception
    + FullyQualifiedErrorId : SPECIFIED_TYPE_NOT_FOUND,Microsoft.PowerShell.Commands.GetFormatDataCommand
    

    Is this all right? And should I just check for $? in the test or something more?
    :)

  6. Jaykul commented on Aug 9, 2018

    @Jaykul
    Contributor

    HANG ON ... This is a breaking change to the function!!!

    Does -ErrorAction SilentlyContinue work, or are you now forcing everyone to wrap this in a try/catch block?

    I understand the desire to have this produce an error, but we can't make existing commands throw exceptions in use cases that used to just return nothing.

    You're breaking every instance of existing code that looks like this, right?

    if(!(Get-FormatData $Type)) {
       Update-FormatData -TypeName $Type ...
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-FixedThe issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions