Skip to content

Non-predefined preference variables aren't type-/value-constrained. #3644

Closed

Description

Related: #3483

Preference variable $ErrorView, despite only supporting 2 values - NormalView and CategorizedView - is defined as a [string] and therefore quietly accepts any value (and falls back to NormalView). [This has been fixed]

It should probably be an enumeration type, as similar preference variables are (e.g., $ErrorActionPreference -is [enum] returns $true)

Similarly, the fact that some preference variables aren't predefined altogether allows their creation with inappropriate types.

Note that this problem exists separately from the fact that creating preference variables in child scopes never enforces their intended types, even if they're appropriately type-constrained in the global scope.

Steps to reproduce

$LogCommandHealthEvent = 'I should be a Boolean'

Expected behavior

(Statement-terminating) errors complaining about the inappropriate values.

Actual behavior

The invalid values are quietly accepted.

Currently, the following preference variables aren't predefined:

  • [bool]: LogCommandHealthEvent LogCommandLifecycleEvent LogEngineHealthEvent LogEngineLifecycleEvent LogProviderLifecycleEvent LogProviderHealthEvent

  • [int]: MaximumAliasCount, MaximumDriveCount, MaximumErrorCount, MaximumFunctionCount, MaximumVariableCount - these are predefined in Windows PowerShell v5.1, however.

  • enum [PSModuleAutoLoadingPreference]: PSModuleAutoLoadingPreference

  • [string]: OFS, but given that it is conceptually [string] and that any value can be converted to a string, that is less of an issue.

  • Others?

Environment data

PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on Darwin Kernel Version 16.5.0: Fri Mar  3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64

Activity

  1. added
    WG-Languageparser, language semantics
    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif
    on Apr 26, 2017
  2. changed the title [-]Preference variable ErrorView and non-predefined preference variables aren't type-/value-constrained.[/-] [+]Non-predefined preference variables aren't type-/value-constrained.[/+] on Mar 5, 2020
  3. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  4. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  5. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  6. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

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

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions