-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Don't require --source when partial source failure leaves a single result #6165
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -981,6 +981,38 @@ namespace AppInstaller::CLI::Workflow | |
| warn << Resource::String::SearchFailureWarning(Utility::LocIndView{ failure.SourceName }) << std::endl; | ||
| } | ||
| } | ||
| // When ShowSearchResultsOnPartialFailure is set (e.g. install) and exactly one match | ||
| // was found, prompt the user interactively rather than failing outright. | ||
| // Falls back to the hard error path if interactivity is disabled. | ||
| else if (WI_IsFlagSet(context.GetFlags(), Execution::ContextFlag::ShowSearchResultsOnPartialFailure) && | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block duplicates a lot of code from the other blocks. I would rather we just accept the error output and move the prompt invocation into the correct location in the existing If a warning about each source is a critical change to you, the entire function could probably be refactored to better make sematic decisions up front and then execute on those using a more common code path:
|
||
| searchResult.Matches.size() == 1 && | ||
| IsInteractivityAllowed(context)) | ||
| { | ||
| { | ||
| auto warn = context.Reporter.Warn(); | ||
| for (const auto& failure : searchResult.Failures) | ||
| { | ||
| warn << Resource::String::SearchFailureWarning(Utility::LocIndView{ failure.SourceName }) << std::endl; | ||
| } | ||
| } | ||
|
|
||
| if (context.Reporter.PromptForBoolResponse(Resource::String::SearchFailureSingleResultPrompt, Reporter::Level::Warning, false)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // User declined; terminate with the source failure HRESULT without re-showing errors | ||
| HRESULT overallHR = S_OK; | ||
| for (const auto& failure : searchResult.Failures) | ||
| { | ||
| HRESULT failureHR = HandleException(nullptr, failure.Exception); | ||
| if (overallHR == S_OK) | ||
| { | ||
| overallHR = failureHR; | ||
| } | ||
| } | ||
| context.SetTerminationHR(overallHR); | ||
| } | ||
| else | ||
| { | ||
| HRESULT overallHR = S_OK; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1332,6 +1332,10 @@ Do you agree to the terms?</value> | |||||
| Please specify one of them using the --source option to proceed.</value> | ||||||
| <comment>{Locked="--source"} "working sources" as in "sources that are working correctly"</comment> | ||||||
| </data> | ||||||
| <data name="SearchFailureSingleResultPrompt" xml:space="preserve"> | ||||||
| <value>A package was found among the working sources. Would you like to proceed?</value> | ||||||
| <comment>"working sources" as in "sources that are working correctly"</comment> | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| </data> | ||||||
| <data name="SearchFailureErrorNoMatches" xml:space="preserve"> | ||||||
| <value>No packages were found among the working sources.</value> | ||||||
| <comment>"working sources" as in "sources that are working correctly"</comment> | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| #include <AppInstallerDownloader.h> | ||
| #include <winget/Settings.h> | ||
| #include <Workflows/DownloadFlow.h> | ||
| #include <Workflows/WorkflowBase.h> | ||
| #include <Commands/InstallCommand.h> | ||
| #include <Commands/SettingsCommand.h> | ||
| #include <Commands/ValidateCommand.h> | ||
|
|
@@ -187,3 +188,64 @@ TEST_CASE("Export_Settings", "[Settings][workflow]") | |
| REQUIRE(userSettingsFileValue.find("settings.json") != std::string::npos); | ||
| } | ||
| } | ||
|
|
||
| TEST_CASE("HandleSearchResultFailures_SingleMatchWithPartialFailure", "[HandleSearchResultFailures][workflow]") | ||
| { | ||
| auto makeSearchResult = []() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
| { | ||
| SearchResult result; | ||
| result.Matches.push_back(ResultMatch{ | ||
| TestCompositePackage::Make(std::vector<Manifest>{ Manifest{} }), | ||
| PackageMatchFilter{ PackageMatchField::Id, MatchType::Exact } | ||
| }); | ||
| result.Failures.push_back({ "FailedSource", std::make_exception_ptr(std::runtime_error("source error")) }); | ||
| return result; | ||
| }; | ||
|
|
||
| SECTION("Interactive_Accept") | ||
| { | ||
| std::istringstream input{ "y\n" }; | ||
| std::ostringstream output; | ||
| TestContext context{ output, input }; | ||
| auto previousThreadGlobals = context.SetForCurrentThread(); | ||
| context.SetFlags(ContextFlag::ShowSearchResultsOnPartialFailure); | ||
| context.Add<Data::SearchResult>(makeSearchResult()); | ||
|
|
||
| context << HandleSearchResultFailures; | ||
|
|
||
| INFO(output.str()); | ||
| REQUIRE_FALSE(context.IsTerminated()); | ||
| REQUIRE(output.str().find("FailedSource") != std::string::npos); | ||
| } | ||
|
|
||
| SECTION("Interactive_Decline") | ||
| { | ||
| std::istringstream input{ "n\n" }; | ||
| std::ostringstream output; | ||
| TestContext context{ output, input }; | ||
| auto previousThreadGlobals = context.SetForCurrentThread(); | ||
| context.SetFlags(ContextFlag::ShowSearchResultsOnPartialFailure); | ||
| context.Add<Data::SearchResult>(makeSearchResult()); | ||
|
|
||
| context << HandleSearchResultFailures; | ||
|
|
||
| INFO(output.str()); | ||
| REQUIRE(context.IsTerminated()); | ||
| } | ||
|
|
||
| SECTION("NonInteractive_HardError") | ||
| { | ||
| std::ostringstream output; | ||
| TestContext context{ output, std::cin }; | ||
| auto previousThreadGlobals = context.SetForCurrentThread(); | ||
| context.SetFlags(ContextFlag::ShowSearchResultsOnPartialFailure); | ||
| context.Args.AddArg(Args::Type::DisableInteractivity); | ||
| context.Add<Data::SearchResult>(makeSearchResult()); | ||
|
|
||
| context << HandleSearchResultFailures; | ||
|
|
||
| INFO(output.str()); | ||
| REQUIRE(context.IsTerminated()); | ||
| REQUIRE(output.str().find("FailedSource") != std::string::npos); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want this to be publicly visible; callers should be required to go through our explicitly defined prompt flows rather than making arbitrary choices about handling interactivity. That also makes the call sites less cluttered, as they are forced to simply invoke a prompt function with a default rather than have control flow.
I think that the correct approach is going to be refactoring the
Reporterprompt methods out intoPromptFlow.cppand have them invoke this function in addition to other checks they do to determine whether to actually prompt or not.