• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2012 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include "update_engine/common/error_code_utils.h"
18 
19 #include <base/strings/string_number_conversions.h>
20 
21 using std::string;
22 
23 namespace chromeos_update_engine {
24 namespace utils {
25 
ErrorCodeToString(ErrorCode code)26 string ErrorCodeToString(ErrorCode code) {
27   // If the given code has both parts (i.e. the error code part and the flags
28   // part) then strip off the flags part since the switch statement below
29   // has case statements only for the base error code or a single flag but
30   // doesn't support any combinations of those.
31   if ((static_cast<int>(code) & static_cast<int>(ErrorCode::kSpecialFlags)) &&
32       (static_cast<int>(code) & ~static_cast<int>(ErrorCode::kSpecialFlags)))
33     code = static_cast<ErrorCode>(
34         static_cast<int>(code) & ~static_cast<int>(ErrorCode::kSpecialFlags));
35   switch (code) {
36     case ErrorCode::kSuccess: return "ErrorCode::kSuccess";
37     case ErrorCode::kError: return "ErrorCode::kError";
38     case ErrorCode::kOmahaRequestError: return "ErrorCode::kOmahaRequestError";
39     case ErrorCode::kOmahaResponseHandlerError:
40       return "ErrorCode::kOmahaResponseHandlerError";
41     case ErrorCode::kFilesystemCopierError:
42       return "ErrorCode::kFilesystemCopierError";
43     case ErrorCode::kPostinstallRunnerError:
44       return "ErrorCode::kPostinstallRunnerError";
45     case ErrorCode::kPayloadMismatchedType:
46       return "ErrorCode::kPayloadMismatchedType";
47     case ErrorCode::kInstallDeviceOpenError:
48       return "ErrorCode::kInstallDeviceOpenError";
49     case ErrorCode::kKernelDeviceOpenError:
50       return "ErrorCode::kKernelDeviceOpenError";
51     case ErrorCode::kDownloadTransferError:
52       return "ErrorCode::kDownloadTransferError";
53     case ErrorCode::kPayloadHashMismatchError:
54       return "ErrorCode::kPayloadHashMismatchError";
55     case ErrorCode::kPayloadSizeMismatchError:
56       return "ErrorCode::kPayloadSizeMismatchError";
57     case ErrorCode::kDownloadPayloadVerificationError:
58       return "ErrorCode::kDownloadPayloadVerificationError";
59     case ErrorCode::kDownloadNewPartitionInfoError:
60       return "ErrorCode::kDownloadNewPartitionInfoError";
61     case ErrorCode::kDownloadWriteError:
62       return "ErrorCode::kDownloadWriteError";
63     case ErrorCode::kNewRootfsVerificationError:
64       return "ErrorCode::kNewRootfsVerificationError";
65     case ErrorCode::kNewKernelVerificationError:
66       return "ErrorCode::kNewKernelVerificationError";
67     case ErrorCode::kSignedDeltaPayloadExpectedError:
68       return "ErrorCode::kSignedDeltaPayloadExpectedError";
69     case ErrorCode::kDownloadPayloadPubKeyVerificationError:
70       return "ErrorCode::kDownloadPayloadPubKeyVerificationError";
71     case ErrorCode::kPostinstallBootedFromFirmwareB:
72       return "ErrorCode::kPostinstallBootedFromFirmwareB";
73     case ErrorCode::kDownloadStateInitializationError:
74       return "ErrorCode::kDownloadStateInitializationError";
75     case ErrorCode::kDownloadInvalidMetadataMagicString:
76       return "ErrorCode::kDownloadInvalidMetadataMagicString";
77     case ErrorCode::kDownloadSignatureMissingInManifest:
78       return "ErrorCode::kDownloadSignatureMissingInManifest";
79     case ErrorCode::kDownloadManifestParseError:
80       return "ErrorCode::kDownloadManifestParseError";
81     case ErrorCode::kDownloadMetadataSignatureError:
82       return "ErrorCode::kDownloadMetadataSignatureError";
83     case ErrorCode::kDownloadMetadataSignatureVerificationError:
84       return "ErrorCode::kDownloadMetadataSignatureVerificationError";
85     case ErrorCode::kDownloadMetadataSignatureMismatch:
86       return "ErrorCode::kDownloadMetadataSignatureMismatch";
87     case ErrorCode::kDownloadOperationHashVerificationError:
88       return "ErrorCode::kDownloadOperationHashVerificationError";
89     case ErrorCode::kDownloadOperationExecutionError:
90       return "ErrorCode::kDownloadOperationExecutionError";
91     case ErrorCode::kDownloadOperationHashMismatch:
92       return "ErrorCode::kDownloadOperationHashMismatch";
93     case ErrorCode::kOmahaRequestEmptyResponseError:
94       return "ErrorCode::kOmahaRequestEmptyResponseError";
95     case ErrorCode::kOmahaRequestXMLParseError:
96       return "ErrorCode::kOmahaRequestXMLParseError";
97     case ErrorCode::kDownloadInvalidMetadataSize:
98       return "ErrorCode::kDownloadInvalidMetadataSize";
99     case ErrorCode::kDownloadInvalidMetadataSignature:
100       return "ErrorCode::kDownloadInvalidMetadataSignature";
101     case ErrorCode::kOmahaResponseInvalid:
102       return "ErrorCode::kOmahaResponseInvalid";
103     case ErrorCode::kOmahaUpdateIgnoredPerPolicy:
104       return "ErrorCode::kOmahaUpdateIgnoredPerPolicy";
105     case ErrorCode::kOmahaUpdateDeferredPerPolicy:
106       return "ErrorCode::kOmahaUpdateDeferredPerPolicy";
107     case ErrorCode::kOmahaErrorInHTTPResponse:
108       return "ErrorCode::kOmahaErrorInHTTPResponse";
109     case ErrorCode::kDownloadOperationHashMissingError:
110       return "ErrorCode::kDownloadOperationHashMissingError";
111     case ErrorCode::kDownloadMetadataSignatureMissingError:
112       return "ErrorCode::kDownloadMetadataSignatureMissingError";
113     case ErrorCode::kOmahaUpdateDeferredForBackoff:
114       return "ErrorCode::kOmahaUpdateDeferredForBackoff";
115     case ErrorCode::kPostinstallPowerwashError:
116       return "ErrorCode::kPostinstallPowerwashError";
117     case ErrorCode::kUpdateCanceledByChannelChange:
118       return "ErrorCode::kUpdateCanceledByChannelChange";
119     case ErrorCode::kUmaReportedMax:
120       return "ErrorCode::kUmaReportedMax";
121     case ErrorCode::kOmahaRequestHTTPResponseBase:
122       return "ErrorCode::kOmahaRequestHTTPResponseBase";
123     case ErrorCode::kResumedFlag:
124       return "Resumed";
125     case ErrorCode::kDevModeFlag:
126       return "DevMode";
127     case ErrorCode::kTestImageFlag:
128       return "TestImage";
129     case ErrorCode::kTestOmahaUrlFlag:
130       return "TestOmahaUrl";
131     case ErrorCode::kSpecialFlags:
132       return "ErrorCode::kSpecialFlags";
133     case ErrorCode::kPostinstallFirmwareRONotUpdatable:
134       return "ErrorCode::kPostinstallFirmwareRONotUpdatable";
135     case ErrorCode::kUnsupportedMajorPayloadVersion:
136       return "ErrorCode::kUnsupportedMajorPayloadVersion";
137     case ErrorCode::kUnsupportedMinorPayloadVersion:
138       return "ErrorCode::kUnsupportedMinorPayloadVersion";
139     case ErrorCode::kOmahaRequestXMLHasEntityDecl:
140       return "ErrorCode::kOmahaRequestXMLHasEntityDecl";
141     case ErrorCode::kFilesystemVerifierError:
142       return "ErrorCode::kFilesystemVerifierError";
143     case ErrorCode::kUserCanceled:
144       return "ErrorCode::kUserCanceled";
145     case ErrorCode::kNonCriticalUpdateInOOBE:
146       return "ErrorCode::kNonCriticalUpdateInOOBE";
147     case ErrorCode::kPayloadTimestampError:
148       return "ErrorCode::kPayloadTimestampError";
149     // Don't add a default case to let the compiler warn about newly added
150     // error codes which should be added here.
151   }
152 
153   return "Unknown error: " + base::UintToString(static_cast<unsigned>(code));
154 }
155 
156 }  // namespace utils
157 }  // namespace chromeos_update_engine
158