winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 532c4417389c43deb5b426083117c1ef1c9cc2f1
parent 6611699078e72115a9ebc1a785048caf5cc3448e
Author: JohnMcPMS <johnmcp@microsoft.com>
Date:   Tue, 17 Mar 2020 23:18:26 -0700

Fix crash when OpenSource returns nullptr (#60)


Diffstat:
Msrc/AppInstallerCLICore/Workflows/InstallFlow.cpp | 4+---
Msrc/AppInstallerCLICore/Workflows/SearchFlow.cpp | 7++++---
Msrc/AppInstallerCLICore/Workflows/ShowFlow.cpp | 4+---
Msrc/AppInstallerCLICore/Workflows/WorkflowBase.cpp | 34+++++++++++++++++++++++++++++++++-
Msrc/AppInstallerCLICore/Workflows/WorkflowBase.h | 2+-
5 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/src/AppInstallerCLICore/Workflows/InstallFlow.cpp b/src/AppInstallerCLICore/Workflows/InstallFlow.cpp @@ -22,9 +22,7 @@ namespace AppInstaller::Workflow } else { - WorkflowBase::IndexSearch(); - - if (WorkflowBase::EnsureOneMatchFromSearchResult()) + if (WorkflowBase::IndexSearch() && WorkflowBase::EnsureOneMatchFromSearchResult()) { GetManifest(); InstallInternal(); diff --git a/src/AppInstallerCLICore/Workflows/SearchFlow.cpp b/src/AppInstallerCLICore/Workflows/SearchFlow.cpp @@ -10,9 +10,10 @@ namespace AppInstaller::Workflow { void SearchFlow::Execute() { - WorkflowBase::IndexSearch(); - - ProcessSearchResult(); + if (WorkflowBase::IndexSearch()) + { + ProcessSearchResult(); + } } void SearchFlow::ProcessSearchResult() diff --git a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp @@ -12,9 +12,7 @@ namespace AppInstaller::Workflow { void ShowFlow::Execute() { - WorkflowBase::IndexSearch(); - - if (WorkflowBase::EnsureOneMatchFromSearchResult()) + if (WorkflowBase::IndexSearch() && WorkflowBase::EnsureOneMatchFromSearchResult()) { if (m_argsRef.Contains(ExecutionArgs::Type::ListVersions)) { diff --git a/src/AppInstallerCLICore/Workflows/WorkflowBase.cpp b/src/AppInstallerCLICore/Workflows/WorkflowBase.cpp @@ -22,9 +22,39 @@ namespace AppInstaller::Workflow m_source = m_reporterRef.ExecuteWithProgress(std::bind(OpenSource, sourceName, std::placeholders::_1)); } - void WorkflowBase::IndexSearch() + bool WorkflowBase::IndexSearch() { OpenIndexSource(); + if (!m_source) + { + bool noSources = true; + + if (m_argsRef.Contains(ExecutionArgs::Type::Source)) + { + // A bad name was given, try to help. + std::vector<SourceDetails> sources = GetSources(); + if (!sources.empty()) + { + noSources = false; + + m_reporterRef.ShowMsg("No sources match the given value '" + *m_argsRef.GetArg(ExecutionArgs::Type::Source) + "'", + ExecutionReporter::Level::Warning); + m_reporterRef.ShowMsg("The configured sources are:"); + for (const auto& details : sources) + { + m_reporterRef.ShowMsg(" " + details.Name); + } + } + } + + if (noSources) + { + m_reporterRef.ShowMsg("No sources defined; add one with 'source add'", + ExecutionReporter::Level::Warning); + } + + return false; + } // Construct query MatchType matchType = MatchType::Substring; @@ -70,6 +100,8 @@ namespace AppInstaller::Workflow } m_searchResult = m_source->Search(searchRequest); + + return true; } bool WorkflowBase::EnsureOneMatchFromSearchResult() diff --git a/src/AppInstallerCLICore/Workflows/WorkflowBase.h b/src/AppInstallerCLICore/Workflows/WorkflowBase.h @@ -20,7 +20,7 @@ namespace AppInstaller::Workflow virtual void OpenIndexSource(); - void IndexSearch(); + bool IndexSearch(); bool EnsureOneMatchFromSearchResult();