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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static async Task<CommandInfo> GetCommandInfoAsync(
.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

{
s_commandInfoCache.TryAdd(commandName, commandInfo);
}
Expand Down