forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrors.cpp
More file actions
107 lines (96 loc) · 4.47 KB
/
Copy pathErrors.cpp
File metadata and controls
107 lines (96 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
#include "pch.h"
#include "Public/AppInstallerErrors.h"
#include "Public/AppInstallerStrings.h"
namespace AppInstaller
{
namespace
{
const char* const GetMessageForAppInstallerHR(HRESULT hr)
{
switch (hr)
{
case APPINSTALLER_CLI_ERROR_INTERNAL_ERROR:
return "Internal Error";
case APPINSTALLER_CLI_ERROR_INVALID_CL_ARGUMENTS:
return "Invalid command line arguments";
case APPINSTALLER_CLI_ERROR_COMMAND_FAILED:
return "Executing command failed";
case APPINSTALLER_CLI_ERROR_MANIFEST_FAILED:
return "Opening manifest failed";
case APPINSTALLER_CLI_ERROR_SHELLEXEC_INSTALL_FAILED:
return "Running ShellExecute failed";
case APPINSTALLER_CLI_ERROR_UNSUPPORTED_MANIFESTVERSION:
return "Cannot process manifest. The manifest version is higher than supported. Please update the client.";
case APPINSTALLER_CLI_ERROR_DOWNLOAD_FAILED:
return "Downloading installer failed";
case APPINSTALLER_CLI_ERROR_CANNOT_WRITE_TO_UPLEVEL_INDEX:
return "Cannot write to index; it is a higher schema version";
case APPINSTALLER_CLI_ERROR_INDEX_INTEGRITY_COMPROMISED:
return "The index is corrupt";
case APPINSTALLER_CLI_ERROR_SOURCES_INVALID:
return "The configured source information is corrupt";
case APPINSTALLER_CLI_ERROR_SOURCE_NAME_ALREADY_EXISTS:
return "The source name is already configured";
case APPINSTALLER_CLI_ERROR_INVALID_SOURCE_TYPE:
return "The source type is invalid";
case APPINSTALLER_CLI_ERROR_PACKAGE_IS_BUNDLE:
return "The MSIX file is a bundle, not a package";
case APPINSTALLER_CLI_ERROR_SOURCE_DATA_MISSING:
return "Data required by the source is missing";
case APPINSTALLER_CLI_ERROR_NO_APPLICABLE_INSTALLER:
return "None of the installers are applicable for the current system";
case APPINSTALLER_CLI_ERROR_INSTALLER_HASH_MISMATCH:
return "The installer file's hash does not match the manifest";
case APPINSTALLER_CLI_ERROR_SOURCE_NAME_DOES_NOT_EXIST:
return "The source name does not exist";
case APPINSTALLER_CLI_ERROR_SOURCE_ARG_ALREADY_EXISTS:
return "The source location is already configured under another name";
case APPINSTALLER_CLI_ERROR_NO_APPLICATIONS_FOUND:
return "No applications found";
case APPINSTALLER_CLI_ERROR_NO_SOURCES_DEFINED:
return "No sources are configured";
case APPINSTALLER_CLI_ERROR_MULTIPLE_APPLICATIONS_FOUND:
return "Multiple applications found matching the criteria";
case APPINSTALLER_CLI_ERROR_NO_MANIFEST_FOUND:
return "No manifest found matching the criteria";
default:
return "Uknown Error Code";
}
}
void GetUserPresentableMessageForHR(std::ostringstream& strstr, HRESULT hr)
{
strstr << "0x" << std::hex << std::setw(8) << std::setfill('0') << hr << " : ";
if (HRESULT_FACILITY(hr) == APPINSTALLER_CLI_ERROR_FACILITY)
{
strstr << GetMessageForAppInstallerHR(hr);
}
else
{
strstr << std::system_category().message(hr);
}
}
}
std::string GetUserPresentableMessage(const wil::ResultException& re)
{
const auto& info = re.GetFailureInfo();
std::ostringstream strstr;
// We assume that if the exception has a message, that message is relevant to show to the user.
if (info.pszMessage)
{
strstr << Utility::ConvertToUTF8(info.pszMessage) << std::endl;
}
GetUserPresentableMessageForHR(strstr, re.GetErrorCode());
return strstr.str();
}
std::string GetUserPresentableMessage(const winrt::hresult_error& hre)
{
return Utility::ConvertToUTF8(hre.message());
}
std::string GetUserPresentableMessage(const std::exception& e)
{
return e.what();
}
}