Skip to content

Commit

Permalink
Add InstallerErrorCode to COM interface (microsoft#1926)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMcPMS authored Feb 11, 2022
1 parent d386744 commit 2006c66
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/Microsoft.Management.Deployment/InstallResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ namespace winrt::Microsoft::Management::Deployment::implementation
{
void InstallResult::Initialize(
winrt::Microsoft::Management::Deployment::InstallResultStatus status,
winrt::hresult extendedErrorCode,
winrt::hresult extendedErrorCode,
uint32_t installerErrorCode,
hstring const& correlationData,
bool rebootRequired)
{
m_status = status;
m_extendedErrorCode = extendedErrorCode;
m_installerErrorCode = installerErrorCode;
m_correlationData = correlationData;
m_rebootRequired = rebootRequired;
}
Expand All @@ -34,4 +36,9 @@ namespace winrt::Microsoft::Management::Deployment::implementation
{
return m_extendedErrorCode;
}

uint32_t InstallResult::InstallerErrorCode()
{
return m_installerErrorCode;
}
}
5 changes: 4 additions & 1 deletion src/Microsoft.Management.Deployment/InstallResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace winrt::Microsoft::Management::Deployment::implementation
#if !defined(INCLUDE_ONLY_INTERFACE_METHODS)
void Initialize(
winrt::Microsoft::Management::Deployment::InstallResultStatus status,
winrt::hresult extendedErrorCode,
winrt::hresult extendedErrorCode,
uint32_t installerErrorCode,
hstring const& correlationData,
bool rebootRequired);
#endif
Expand All @@ -21,13 +22,15 @@ namespace winrt::Microsoft::Management::Deployment::implementation
bool RebootRequired();
winrt::Microsoft::Management::Deployment::InstallResultStatus Status();
winrt::hresult ExtendedErrorCode();
uint32_t InstallerErrorCode();

#if !defined(INCLUDE_ONLY_INTERFACE_METHODS)
private:
std::wstring m_correlationData = L"";
bool m_rebootRequired = false;
winrt::Microsoft::Management::Deployment::InstallResultStatus m_status = winrt::Microsoft::Management::Deployment::InstallResultStatus::Ok;
winrt::hresult m_extendedErrorCode = S_OK;
uint32_t m_installerErrorCode = 0;
#endif
};
}
17 changes: 11 additions & 6 deletions src/Microsoft.Management.Deployment/PackageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ namespace winrt::Microsoft::Management::Deployment::implementation
return *packageCatalogImpl;
}

winrt::Microsoft::Management::Deployment::InstallResult GetInstallResult(::Workflow::ExecutionStage executionStage, winrt::hresult terminationHR, winrt::hstring correlationData, bool rebootRequired)
winrt::Microsoft::Management::Deployment::InstallResult GetInstallResult(::Workflow::ExecutionStage executionStage, winrt::hresult terminationHR, uint32_t installerError, winrt::hstring correlationData, bool rebootRequired)
{
winrt::Microsoft::Management::Deployment::InstallResultStatus installResultStatus = GetInstallResultStatus(executionStage, terminationHR);
auto installResult = winrt::make_self<wil::details::module_count_wrapper<winrt::Microsoft::Management::Deployment::implementation::InstallResult>>();
installResult->Initialize(installResultStatus, terminationHR, correlationData, rebootRequired);
installResult->Initialize(installResultStatus, terminationHR, installerError, correlationData, rebootRequired);
return *installResult;
}

Expand Down Expand Up @@ -406,6 +406,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
bool isUpgrade = false)
{
winrt::hresult terminationHR = S_OK;
uint32_t installerError = 0;
hstring correlationData = (options) ? options.CorrelationData() : L"";
::Workflow::ExecutionStage executionStage = ::Workflow::ExecutionStage::Initial;

Expand Down Expand Up @@ -435,12 +436,12 @@ namespace winrt::Microsoft::Management::Deployment::implementation
if (!(options.AllowUpgradeToUnknownVersion() &&
AppInstaller::Utility::ICUCaseInsensitiveEquals(installedVersion.GetChannel().ToString(), upgradeVersion.GetChannel().ToString())))
{
co_return GetInstallResult(executionStage, APPINSTALLER_CLI_ERROR_UPGRADE_VERSION_UNKNOWN, correlationData, false);
co_return GetInstallResult(executionStage, APPINSTALLER_CLI_ERROR_UPGRADE_VERSION_UNKNOWN, 0, correlationData, false);
}
}
else if (!installedVersion.IsUpdatedBy(upgradeVersion))
{
co_return GetInstallResult(executionStage, APPINSTALLER_CLI_ERROR_UPGRADE_VERSION_NOT_NEWER, correlationData, false);
co_return GetInstallResult(executionStage, APPINSTALLER_CLI_ERROR_UPGRADE_VERSION_NOT_NEWER, 0, correlationData, false);
}

// Set upgrade flag
Expand Down Expand Up @@ -537,12 +538,16 @@ namespace winrt::Microsoft::Management::Deployment::implementation
// The install command has finished, check for success/failure and how far it got.
terminationHR = queueItem->GetContext().GetTerminationHR();
executionStage = queueItem->GetContext().GetExecutionStage();
if (queueItem->GetContext().Contains(Data::InstallerReturnCode))
{
installerError = static_cast<uint32_t>(queueItem->GetContext().Get<Data::InstallerReturnCode>());
}
}
}
WINGET_CATCH_STORE(terminationHR, APPINSTALLER_CLI_ERROR_COMMAND_FAILED);

// TODO - RebootRequired not yet populated, msi arguments not returned from Execute.
co_return GetInstallResult(executionStage, terminationHR, correlationData, false);
co_return GetInstallResult(executionStage, terminationHR, installerError, correlationData, false);
}

winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Microsoft::Management::Deployment::InstallResult, winrt::Microsoft::Management::Deployment::InstallProgress> GetEmptyAsynchronousResultForInstallOperation(
Expand All @@ -551,7 +556,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
{
// If a function uses co_await or co_return (i.e. if it is a co_routine), it cannot use return directly.
// This helper helps a function that is not a coroutine itself to return errors asynchronously.
co_return GetInstallResult(::Workflow::ExecutionStage::Initial, hr, correlationData, false);
co_return GetInstallResult(::Workflow::ExecutionStage::Initial, hr, 0, correlationData, false);
}

#define WINGET_RETURN_INSTALL_RESULT_HR_IF(hr, boolVal) { if(boolVal) { return GetEmptyAsynchronousResultForInstallOperation(hr, correlationData); }}
Expand Down
9 changes: 8 additions & 1 deletion src/Microsoft.Management.Deployment/PackageManager.idl
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ namespace Microsoft.Management.Deployment

/// Batched error code, example APPINSTALLER_CLI_ERROR_SHELLEXEC_INSTALL_FAILED
InstallResultStatus Status{ get; };
/// Specific error if known, from downloader or installer itself, example ERROR_INSTALL_PACKAGE_REJECTED
/// The error code of the overall operation.
HRESULT ExtendedErrorCode{ get; };

[contract(Microsoft.Management.Deployment.WindowsPackageManagerContract, 4)]
{
/// The error code from the install attempt. Only valid if the Status is InstallError.
/// This value's meaning will require knowledge of the specific installer or install technology.
UInt32 InstallerErrorCode{ get; };
}
}

/// IMPLEMENTATION NOTE: SourceOrigin from winget/RepositorySource.h
Expand Down
Binary file not shown.
4 changes: 3 additions & 1 deletion tools/SampleWinGetUWPCaller/AppInstallerCaller/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,10 @@ namespace winrt::AppInstallerCaller::implementation
}
else
{
std::wostringstream failText;
failText << L"Install failed: " << installResult.ExtendedErrorCode() << L" [" << installResult.InstallerErrorCode() << L"]";
installButton.Content(box_value(L"Install"));
statusText.Text(L"Install failed.");
statusText.Text(failText.str());
}
}

Expand Down
2 changes: 2 additions & 0 deletions tools/SampleWinGetUWPCaller/AppInstallerCaller/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
#include <winrt/Windows.UI.Xaml.Interop.h>
#include <winrt/Windows.UI.Xaml.Markup.h>
#include <winrt/Windows.UI.Xaml.Navigation.h>

#include <sstream>

0 comments on commit 2006c66

Please sign in to comment.