Skip to content

Fix invalid argument handling for workload search version - #55682

Merged
marcpopMSFT merged 3 commits into
mainfrom
marcpopmsft-fix-workload-search-version-errors
Aug 11, 2026
Merged

marcpopMSFT merged 3 commits into
mainfrom
marcpopmsft-fix-workload-search-version-errors

Conversation

@marcpopMSFT

@marcpopMSFT marcpopMSFT commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Summary

  • preserve all three supported dotnet workload search version modes:
    • no arguments to list workload-set versions
    • one or more package@version arguments to find matching workload sets
    • exactly one workload-set package version to inspect that set
  • reject mixed or multiple non-component arguments through the normal CLI parsing path instead of throwing InvalidOperationException
  • add regression coverage for mistyped options such as -foo bar and assert the localized unrecognized-argument message

This is intentionally compatible with #55681, which adds NuGet options to the same command. Recognized options continue to parse as options, while typos captured by the variadic positional argument now fail cleanly.

Help-output behavior is intentionally unchanged and will be addressed separately.

Validation

  • build.cmd
  • GivenInvalidArgumentToWorkloadSearchVersionItFailsCleanly (6 cases)
  • built SDK invocation returns help plus Unrecognized command or argument '-foo bar' with exit code 1

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: c380ce6f-a051-44c6-810f-46d8c8d6b747
Copilot AI review requested due to automatic review settings August 7, 2026 18:55
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes argument validation for dotnet workload search version so the command reliably supports its three intended modes while ensuring invalid inputs fail via standard CLI parsing (rather than throwing InvalidOperationException). It also adds a regression test to assert the localized “unrecognized argument” message for mistyped option-like inputs captured by the variadic positional argument.

Changes:

  • Adjust workload search version validation to correctly distinguish: no args (list), package@version args (match sets), and a single workload-set version (inspect set).
  • Prevent invalid combinations (mixed or multiple non-component args) from reaching execution paths that can throw due to .Single()/SingleOrDefault() misuse.
  • Add test coverage asserting the localized unrecognized-argument message for inputs like -foo bar.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
test/dotnet.Tests/CommandTests/Workload/Search/GivenDotnetWorkloadSearch.cs Extends regression coverage to include option-like typos and asserts the localized unrecognized-argument message.
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Workload/WorkloadSearchVersionsCommandDefinition.cs Updates validator logic to safely handle multiple/invalid arguments without throwing and to preserve the three supported invocation modes.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: c380ce6f-a051-44c6-810f-46d8c8d6b747
@marcpopMSFT
marcpopMSFT requested a review from a team as a code owner August 7, 2026 22:19
@marcpopMSFT

marcpopMSFT commented Aug 7, 2026 •

Copy link
Copy Markdown
Member Author

Tested in codespace and confirmed I could still do search version actions but if I did invalid commands, it worked. It was showing the whole help on error and I asked it to fix that. Confirmed that an error no longer spits out the full help and help still works.

@marcpopMSFT
marcpopMSFT enabled auto-merge (squash) August 10, 2026 21:23
@marcpopMSFT
marcpopMSFT requested a review from baronfel August 11, 2026 20:31

@baronfel baronfel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The core fix looks good, but the top-level showhelp wrapper is gross as heck. I'll approve once your agent is done removing that :D

Keep help-output changes out of this targeted argument-validation fix.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: c380ce6f-a051-44c6-810f-46d8c8d6b747
@marcpopMSFT
marcpopMSFT merged commit d8fe720 into main Aug 11, 2026
21 checks passed
@marcpopMSFT
marcpopMSFT deleted the marcpopmsft-fix-workload-search-version-errors branch August 11, 2026 22:07
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Aug 15, 2026
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.

3 participants