Skip to content

Fix when no CommandInfo comes back #1276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

TylerLeonhardt
Copy link
Member

Before this PSES drops an exception in the log. It's "handled" so the extension doesn't break down... but we don't want the stacktrace in the log.

The behavior is still the same, this just prevents when Get-Command returns nothing.

@@ -96,7 +96,7 @@ internal static class CommandHelpers
.FirstOrDefault();

// Only cache CmdletInfos since they're exposed in binaries they are likely to not change throughout the session.
if (commandInfo.CommandType == CommandTypes.Cmdlet)
if (commandInfo?.CommandType == CommandTypes.Cmdlet)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have crashed here before this change if commandInfo was null. Now that the code will get past here, do the callers of this method properly handle a null return value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. They handle a null value. The change I added with the caching is what didn't handle a null value

@TylerLeonhardt TylerLeonhardt merged commit 7a828a0 into PowerShell:master Apr 29, 2020
@TylerLeonhardt TylerLeonhardt deleted the fix-when-no-commandInfo-comes-back branch April 29, 2020 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants