abcdefg
abcdefgh
abcdefg
It should show a suggestion after all three commands above
The suggestion is only shown after the first unknown command
PS C:\> abcdefg
abcdefg : The term 'abcdefg' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ abcdefg
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (abcdefg:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Suggestion [4,General]: The most similar commands are: cd, del, ac, clear, diff, cd.., cd\, alg.exe, at.exe, calc.exe.
PS C:\> abcdefgh
abcdefgh : The term 'abcdefgh' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ abcdefgh
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (abcdefgh:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\> abcdefg
abcdefg : The term 'abcdefg' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ abcdefg
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (abcdefg:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\>
Name Value
---- -----
PSVersion 7.0.0-preview.4
PSEdition Core
GitCommitId 7.0.0-preview.4
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
This happens only if the commands are copy pasted together to console.
This happens only if the commands are copy pasted together to console.
You don't need to copy and paste the commands to repro this.
@0xd4d Can you elaborate on how you executed those invalid expressions. When I execute it one by one or with semicolons in a line, I get suggestions for all.
Did you try typing them in? Did you try longer strings?
abcdefg works, abcdefgh doesn'taaaaaa works, aaaaaaa doesn'tI debugged it and stopped when an ArgumentNullException was thrown and found this script block on the stack. Looks like Get-Command $lastError... returns null.
Interesting, as you mentioned it fails for long strings, but not for all long strings(gabcdefs,getcommand works). I think its not finding a match for those strings, hence nothing is printed.
Cc: @SteveL-MSFT
The current "suggestion framework" is pretty primitive. We have an open issue to fix this so that suggestions are part of ErrorRecords rather than scrub later. In this case, it seems that line 72 should check if anything was returned. Since the current algorithm uses fuzzy matching, repro depends on what is on your system and what results get returned from the fuzzy matching. It seems reasonable that after a certain length of characters, it wouldn't actually match anything reasonable on your system.
I have a mostly-working WIP implementation of Suggestions-on-ErrorRecord over in #9115
It's largely functional, just stuck on some test failures. If there's interest in having that available for PS7 I can look at bumping it up my priority list. Might need a hand with some of the odder failures that are cropping up, though. 馃檪
But as Steve says... suggestions can only really do so much. We can always expand the fuzzy matching to be more "clever" in various ways, I'm sure, but at the end of the day we would want to restrict what it can do to reasonable levels so we don't have any hanging when errors occur.