Skip to content

Commit 3e9efad

Browse files
Stop composite source after JSON open failures
1 parent 8ad1a29 commit 3e9efad

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/AppInstallerCLICore/Workflows/WorkflowBase.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,10 @@ namespace AppInstaller::CLI::Workflow
10371037

10381038
// Open the predefined source.
10391039
context << OpenPredefinedSource(m_predefinedSource, m_forDependencies);
1040+
if (context.IsTerminated())
1041+
{
1042+
return;
1043+
}
10401044

10411045
// Create the composite source from the two.
10421046
Repository::Source source;

src/AppInstallerCLITests/UpdateFlow.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,33 @@ TEST_CASE("ListFlow_JsonOutputBadSource", "[ListFlow][workflow]")
435435
REQUIRE(context.GetTerminationHR() == APPINSTALLER_CLI_ERROR_SOURCE_NAME_DOES_NOT_EXIST);
436436
}
437437

438+
TEST_CASE("ListFlow_JsonOutputStopsCompositeAfterInstalledSourceFailure", "[ListFlow][workflow]")
439+
{
440+
std::ostringstream listOutput;
441+
TestContext context{ listOutput, std::cin };
442+
auto previousThreadGlobals = context.SetForCurrentThread();
443+
context.Args.AddArg(Execution::Args::Type::OutputFormat, "json"sv);
444+
Workflow::SetJsonOutputChannel(context);
445+
446+
auto availableSource = AppInstaller::Repository::Source{ CreateTestSource({ TSR::TestInstaller_Exe }) };
447+
context.Add<Execution::Data::Source>(availableSource);
448+
context.Override({ "OpenPredefinedSource", [](TestContext& context)
449+
{
450+
context.Reporter.Json() << R"({"packages":[],"truncated":false,"sourceFailures":[],"error":{"code":"0x8a15000e","message":"Failed to open source."}})" << std::endl;
451+
context.SetTerminationHR(APPINSTALLER_CLI_ERROR_SOURCE_OPEN_FAILED);
452+
} });
453+
454+
context << Workflow::OpenCompositeSource(AppInstaller::Repository::PredefinedSource::Installed);
455+
INFO(listOutput.str());
456+
457+
Json::Value json = ConvertToJson(listOutput.str());
458+
REQUIRE(json["packages"].isArray());
459+
REQUIRE(json["packages"].empty());
460+
REQUIRE(json["error"]["code"].asString() == "0x8a15000e");
461+
REQUIRE(context.GetTerminationHR() == APPINSTALLER_CLI_ERROR_SOURCE_OPEN_FAILED);
462+
REQUIRE_FALSE(context.Get<Execution::Data::Source>().IsComposite());
463+
}
464+
438465
TEST_CASE("UpdateFlow_ListJsonOutput", "[UpdateFlow][workflow]")
439466
{
440467
std::ostringstream updateOutput;

0 commit comments

Comments
 (0)