Skip to content

Misleading error message when parsing Configuration keyword on ARM processor #18781

@ajhall

Description

@ajhall

Prerequisites

Steps to reproduce

When I work on PowerShell DSC files on an ARM-based Mac, the PowerShell extension for VS Code claims that I'm in constrained language mode and warns that I can't use the Configuration keyword.

To reproduce:

  1. Use an ARM-based Mac.
  2. Ensure Constrained Language Mode is disabled.
PS> $ExecutionContext.SessionState.LanguageMode
FullLanguage
  1. Parse a script containing the Configuration keyword.
$errors = $null
[System.Management.Automation.PSParser]::Tokenize("Configuration MyConfig {}",[ref]$errors)
  1. View the resulting errors.
PS> $errors

Token                                Message
-----                                -------
System.Management.Automation.PSToken Configuration keyword is not allowed in constrainedLanguage mode.

Expected behavior

The Configuration keyword should be supported, or the error message should accurately state why it's not supported.

Actual behavior

The error message claims constrainedLanguage mode is enabled, which isn't true.

I believe this is caused by this block of code, which checks that either:

  1. ConstrainedLanguage mode is enabled, or
  2. The processor type is ARM.

// Configuration is not supported on ARM or in ConstrainedLanguage
if (PsUtils.IsRunningOnProcessorArchitectureARM() || Runspace.DefaultRunspace.ExecutionContext.LanguageMode == PSLanguageMode.ConstrainedLanguage)
{
ReportError(configurationToken.Extent,
nameof(ParserStrings.ConfigurationNotAllowedInConstrainedLanguage),
ParserStrings.ConfigurationNotAllowedInConstrainedLanguage,
configurationToken.Kind.Text());
return null;
}

It uses the same error message ("Configuration keyword is not allowed in constrainedLanguage mode.") even if the real issue is that I'm using an ARM processor.

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Darwin 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

From the Visual Studio Code PowerShell extension:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions