PowerShell icon indicating copy to clipboard operation
PowerShell copied to clipboard

Powershell fails to report similar commands upon entering unknown command

Open RohitRRao370 opened this issue 11 months ago • 9 comments

Prerequisites

Steps to reproduce

  1. Open powershell
  2. Type a powershell command but misspelled, like pws (as in typo of pwd) or ld (typo of ls)
  3. View the output

Expected behavior

PS>pws
pws: The term 'pws' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Suggestion [4,General]: The most similar commands are:
pwd

Actual behavior

PS>pws
pws: The term 'pws' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Suggestion [4,General]: The most similar commands are:

Error details

PS> Get-Error
Exception             :
    Type        : System.Management.Automation.CommandNotFoundException
    ErrorRecord :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : The term 'pws' is not recognized as a name of a cmdlet, function, script file, or executable
program.
                      Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
            HResult : -2146233087
        TargetObject          : pws
        CategoryInfo          : ObjectNotFound: (pws:String) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : CommandNotFoundException
        InvocationInfo        :
            ScriptLineNumber : 1
            OffsetInLine     : 1
            HistoryId        : 5
            Line             : pws
            Statement        : pws
            PositionMessage  : At line:1 char:1
                               + pws
                               + ~~~
            InvocationName   : pws
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    CommandName : pws
    TargetSite  :
        Name          : LookupCommandInfo
        DeclaringType : [System.Management.Automation.CommandDiscovery]
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message     : The term 'pws' is not recognized as a name of a cmdlet, function, script file, or executable program.
                  Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
    Data        : System.Collections.ListDictionaryInternal
    Source      : System.Management.Automation
    HResult     : -2146233087
    StackTrace  :
   at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandTypes commandTypes,
SearchResolutionOptions searchResolutionOptions, CommandOrigin commandOrigin, ExecutionContext context)
   at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)
   at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[]
commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput,
CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][]
commandRedirections, FunctionContext funcContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject          : pws
CategoryInfo          : ObjectNotFound: (pws:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
InvocationInfo        :
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 5
    Line             : pws
    Statement        : pws
    PositionMessage  : At line:1 char:1
                       + pws
                       + ~~~
    InvocationName   : pws
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

PS>$PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.5.1
PSEdition                      Core
GitCommitId                    7.5.1
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

RohitRRao370 avatar Apr 25 '25 06:04 RohitRRao370

It works in my environment

Image

237dmitry avatar Apr 25 '25 08:04 237dmitry

@237dmitry That's odd I might have messed with the settings somewhere on accident, do you know of anything that may have caused this?

RohitRRao370 avatar Apr 25 '25 10:04 RohitRRao370

Just one guess, check Experimental Features:

$ Get-ExperimentalFeature PSFeedbackProvider | fl

Name        : PSFeedbackProvider
Enabled     : True
Source      : PSEngine
Description : Replace the hard-coded suggestion framework with the extensible feedback provider

This may be related to the topic, but I'm not sure.

237dmitry avatar Apr 25 '25 10:04 237dmitry

Yes, the experimental PSFeedbackProvider feature must be enabled, which by default is not the case in stable (as opposed to preview) versions.

This problem has been known for a while, and it was decided not to fix it:

  • https://github.com/PowerShell/PowerShell/issues/20916#issuecomment-1859262947

The expectation then was that the experimental feature would become a stable one in v7.5.0, but that hasn't happened.

Thus, the problem will go away in 7.6.0 at the earliest (presumptive release data is late this year / early 2026), assuming that the experimental feature will become a stable one then.

For now, Enable-ExperimentalFeature PSFeedbackProvider is a workaround.

mklement0 avatar Apr 25 '25 11:04 mklement0

@mklement0 Aha, thanks! I suppose that makes this redundant then, I'll close it

RohitRRao370 avatar Apr 25 '25 13:04 RohitRRao370

@RohitRRao370, it may actually be better to keep the issue open, to make it - along with the explanation - easier to discover by users encountering the issue in the future.

To keep it open longer than 6 months, however, would require a member of the team to label it as Keep-Open.

mklement0 avatar Apr 25 '25 17:04 mklement0

@mklement0 Good point. Aight then, I'll reopen it.

RohitRRao370 avatar Apr 26 '25 01:04 RohitRRao370

I just want to add to this discussion as I ran into a related issue: I was getting blank Suggestion [4,General]: The most similar commands are: when unloading/loading posh-git from the current powershell session. It seems like this suggestion output appears when there is any population in $Error.

So, if you are getting Suggestion [4,General]: The most similar commands are: pollution after running commands, the fix is to enable the PSFeedbackProvider experimental feature:

Enable-ExperimentalFeature -Name PSFeedbackProvider

I don't know why enabling this feature suppresses the suggestion output, but it does. If someone can add to the discussion on why - that would be great.

futuremotiondev avatar Apr 28 '25 04:04 futuremotiondev

Interesting, @futuremotiondev - I don't see the same behavior in general (I cannot reproduce it by unloading or loading the posh-git module).

Instead, I see behavior that is consistent with the issue at hand, which means that enabling the experimental feature doesn't suppress the message, but completes it (i.e. it bypasses the bug at hand) and also reformats it; e.g., after submitting pws:

Image

mklement0 avatar May 02 '25 22:05 mklement0

You definitely should see the warning emitted from posh-git if you unload it from the current session via Remove-Module. The warning is hard-coded here and fires during $ExecutionContext.SessionState.Module.OnRemove no matter what.

Regarding the feedback provider, it does also work for me if I submit pws. (Although it's not listing wps, guessing that might be an alias I don't have defined)

Regarding unloading of posh-git, the problems are arising only after miniconda3 has been unloaded:

Remove-Module -FullyQualifiedName "$Env:_CONDA_ROOT\shell\condabin\Conda.psm1"

When I unload conda.psm1 as above, it breaks my prompt and fills $Error with exceptions that complain 'prompt' is not recognized as a name of a cmdlet, function, script file, or executable program..

I'm going to have to take a look into miniconda's load/unload behavior. I think it's deleting the prompt function entirely. Either way I think miniconda is outside the scope of this thread so I'll do my own research there rather than hijack this thread.

futuremotiondev avatar May 07 '25 21:05 futuremotiondev

You definitely should see the warning

Per the source-code link, the warning is only emitted if someone else modified the prompt function that the posh-git module provided.

Although it's not listing wps

wps is a built-in alias of Wait-Process

mklement0 avatar May 07 '25 21:05 mklement0

This issue should've been fixed by https://github.com/PowerShell/PowerShell/pull/25177. The legacy suggestion for fuzzy command names is removed, so you will have to enable PSFeedbackProvider if you want to see the command name suggestions for typos.

daxian-dbw avatar Aug 25 '25 19:08 daxian-dbw

📣 Hey @@RohitRRao370, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback