| Alex Deymo | e88e9fe | 2016-02-03 16:38:00 -0800 | [diff] [blame] | 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 |  | 
|  | 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))) | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 33 | code = static_cast<ErrorCode>(static_cast<int>(code) & | 
|  | 34 | ~static_cast<int>(ErrorCode::kSpecialFlags)); | 
| Alex Deymo | e88e9fe | 2016-02-03 16:38:00 -0800 | [diff] [blame] | 35 | switch (code) { | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 36 | case ErrorCode::kSuccess: | 
|  | 37 | return "ErrorCode::kSuccess"; | 
|  | 38 | case ErrorCode::kError: | 
|  | 39 | return "ErrorCode::kError"; | 
|  | 40 | case ErrorCode::kOmahaRequestError: | 
|  | 41 | return "ErrorCode::kOmahaRequestError"; | 
| Alex Deymo | e88e9fe | 2016-02-03 16:38:00 -0800 | [diff] [blame] | 42 | case ErrorCode::kOmahaResponseHandlerError: | 
|  | 43 | return "ErrorCode::kOmahaResponseHandlerError"; | 
|  | 44 | case ErrorCode::kFilesystemCopierError: | 
|  | 45 | return "ErrorCode::kFilesystemCopierError"; | 
|  | 46 | case ErrorCode::kPostinstallRunnerError: | 
|  | 47 | return "ErrorCode::kPostinstallRunnerError"; | 
|  | 48 | case ErrorCode::kPayloadMismatchedType: | 
|  | 49 | return "ErrorCode::kPayloadMismatchedType"; | 
|  | 50 | case ErrorCode::kInstallDeviceOpenError: | 
|  | 51 | return "ErrorCode::kInstallDeviceOpenError"; | 
|  | 52 | case ErrorCode::kKernelDeviceOpenError: | 
|  | 53 | return "ErrorCode::kKernelDeviceOpenError"; | 
|  | 54 | case ErrorCode::kDownloadTransferError: | 
|  | 55 | return "ErrorCode::kDownloadTransferError"; | 
|  | 56 | case ErrorCode::kPayloadHashMismatchError: | 
|  | 57 | return "ErrorCode::kPayloadHashMismatchError"; | 
|  | 58 | case ErrorCode::kPayloadSizeMismatchError: | 
|  | 59 | return "ErrorCode::kPayloadSizeMismatchError"; | 
|  | 60 | case ErrorCode::kDownloadPayloadVerificationError: | 
|  | 61 | return "ErrorCode::kDownloadPayloadVerificationError"; | 
|  | 62 | case ErrorCode::kDownloadNewPartitionInfoError: | 
|  | 63 | return "ErrorCode::kDownloadNewPartitionInfoError"; | 
|  | 64 | case ErrorCode::kDownloadWriteError: | 
|  | 65 | return "ErrorCode::kDownloadWriteError"; | 
|  | 66 | case ErrorCode::kNewRootfsVerificationError: | 
|  | 67 | return "ErrorCode::kNewRootfsVerificationError"; | 
|  | 68 | case ErrorCode::kNewKernelVerificationError: | 
|  | 69 | return "ErrorCode::kNewKernelVerificationError"; | 
|  | 70 | case ErrorCode::kSignedDeltaPayloadExpectedError: | 
|  | 71 | return "ErrorCode::kSignedDeltaPayloadExpectedError"; | 
|  | 72 | case ErrorCode::kDownloadPayloadPubKeyVerificationError: | 
|  | 73 | return "ErrorCode::kDownloadPayloadPubKeyVerificationError"; | 
|  | 74 | case ErrorCode::kPostinstallBootedFromFirmwareB: | 
|  | 75 | return "ErrorCode::kPostinstallBootedFromFirmwareB"; | 
|  | 76 | case ErrorCode::kDownloadStateInitializationError: | 
|  | 77 | return "ErrorCode::kDownloadStateInitializationError"; | 
|  | 78 | case ErrorCode::kDownloadInvalidMetadataMagicString: | 
|  | 79 | return "ErrorCode::kDownloadInvalidMetadataMagicString"; | 
|  | 80 | case ErrorCode::kDownloadSignatureMissingInManifest: | 
|  | 81 | return "ErrorCode::kDownloadSignatureMissingInManifest"; | 
|  | 82 | case ErrorCode::kDownloadManifestParseError: | 
|  | 83 | return "ErrorCode::kDownloadManifestParseError"; | 
|  | 84 | case ErrorCode::kDownloadMetadataSignatureError: | 
|  | 85 | return "ErrorCode::kDownloadMetadataSignatureError"; | 
|  | 86 | case ErrorCode::kDownloadMetadataSignatureVerificationError: | 
|  | 87 | return "ErrorCode::kDownloadMetadataSignatureVerificationError"; | 
|  | 88 | case ErrorCode::kDownloadMetadataSignatureMismatch: | 
|  | 89 | return "ErrorCode::kDownloadMetadataSignatureMismatch"; | 
|  | 90 | case ErrorCode::kDownloadOperationHashVerificationError: | 
|  | 91 | return "ErrorCode::kDownloadOperationHashVerificationError"; | 
|  | 92 | case ErrorCode::kDownloadOperationExecutionError: | 
|  | 93 | return "ErrorCode::kDownloadOperationExecutionError"; | 
|  | 94 | case ErrorCode::kDownloadOperationHashMismatch: | 
|  | 95 | return "ErrorCode::kDownloadOperationHashMismatch"; | 
|  | 96 | case ErrorCode::kOmahaRequestEmptyResponseError: | 
|  | 97 | return "ErrorCode::kOmahaRequestEmptyResponseError"; | 
|  | 98 | case ErrorCode::kOmahaRequestXMLParseError: | 
|  | 99 | return "ErrorCode::kOmahaRequestXMLParseError"; | 
|  | 100 | case ErrorCode::kDownloadInvalidMetadataSize: | 
|  | 101 | return "ErrorCode::kDownloadInvalidMetadataSize"; | 
|  | 102 | case ErrorCode::kDownloadInvalidMetadataSignature: | 
|  | 103 | return "ErrorCode::kDownloadInvalidMetadataSignature"; | 
|  | 104 | case ErrorCode::kOmahaResponseInvalid: | 
|  | 105 | return "ErrorCode::kOmahaResponseInvalid"; | 
|  | 106 | case ErrorCode::kOmahaUpdateIgnoredPerPolicy: | 
|  | 107 | return "ErrorCode::kOmahaUpdateIgnoredPerPolicy"; | 
|  | 108 | case ErrorCode::kOmahaUpdateDeferredPerPolicy: | 
|  | 109 | return "ErrorCode::kOmahaUpdateDeferredPerPolicy"; | 
|  | 110 | case ErrorCode::kOmahaErrorInHTTPResponse: | 
|  | 111 | return "ErrorCode::kOmahaErrorInHTTPResponse"; | 
|  | 112 | case ErrorCode::kDownloadOperationHashMissingError: | 
|  | 113 | return "ErrorCode::kDownloadOperationHashMissingError"; | 
|  | 114 | case ErrorCode::kDownloadMetadataSignatureMissingError: | 
|  | 115 | return "ErrorCode::kDownloadMetadataSignatureMissingError"; | 
|  | 116 | case ErrorCode::kOmahaUpdateDeferredForBackoff: | 
|  | 117 | return "ErrorCode::kOmahaUpdateDeferredForBackoff"; | 
|  | 118 | case ErrorCode::kPostinstallPowerwashError: | 
|  | 119 | return "ErrorCode::kPostinstallPowerwashError"; | 
|  | 120 | case ErrorCode::kUpdateCanceledByChannelChange: | 
|  | 121 | return "ErrorCode::kUpdateCanceledByChannelChange"; | 
|  | 122 | case ErrorCode::kUmaReportedMax: | 
|  | 123 | return "ErrorCode::kUmaReportedMax"; | 
|  | 124 | case ErrorCode::kOmahaRequestHTTPResponseBase: | 
|  | 125 | return "ErrorCode::kOmahaRequestHTTPResponseBase"; | 
|  | 126 | case ErrorCode::kResumedFlag: | 
|  | 127 | return "Resumed"; | 
|  | 128 | case ErrorCode::kDevModeFlag: | 
|  | 129 | return "DevMode"; | 
|  | 130 | case ErrorCode::kTestImageFlag: | 
|  | 131 | return "TestImage"; | 
|  | 132 | case ErrorCode::kTestOmahaUrlFlag: | 
|  | 133 | return "TestOmahaUrl"; | 
|  | 134 | case ErrorCode::kSpecialFlags: | 
|  | 135 | return "ErrorCode::kSpecialFlags"; | 
|  | 136 | case ErrorCode::kPostinstallFirmwareRONotUpdatable: | 
|  | 137 | return "ErrorCode::kPostinstallFirmwareRONotUpdatable"; | 
|  | 138 | case ErrorCode::kUnsupportedMajorPayloadVersion: | 
|  | 139 | return "ErrorCode::kUnsupportedMajorPayloadVersion"; | 
|  | 140 | case ErrorCode::kUnsupportedMinorPayloadVersion: | 
|  | 141 | return "ErrorCode::kUnsupportedMinorPayloadVersion"; | 
|  | 142 | case ErrorCode::kOmahaRequestXMLHasEntityDecl: | 
|  | 143 | return "ErrorCode::kOmahaRequestXMLHasEntityDecl"; | 
|  | 144 | case ErrorCode::kFilesystemVerifierError: | 
|  | 145 | return "ErrorCode::kFilesystemVerifierError"; | 
|  | 146 | case ErrorCode::kUserCanceled: | 
|  | 147 | return "ErrorCode::kUserCanceled"; | 
| Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 148 | case ErrorCode::kNonCriticalUpdateInOOBE: | 
|  | 149 | return "ErrorCode::kNonCriticalUpdateInOOBE"; | 
| Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 150 | case ErrorCode::kOmahaUpdateIgnoredOverCellular: | 
|  | 151 | return "ErrorCode::kOmahaUpdateIgnoredOverCellular"; | 
| Sen Jiang | 8e768e9 | 2017-06-28 17:13:19 -0700 | [diff] [blame] | 152 | case ErrorCode::kPayloadTimestampError: | 
|  | 153 | return "ErrorCode::kPayloadTimestampError"; | 
| Sen Jiang | fe52282 | 2017-10-31 15:14:11 -0700 | [diff] [blame] | 154 | case ErrorCode::kUpdatedButNotActive: | 
|  | 155 | return "ErrorCode::kUpdatedButNotActive"; | 
| Sen Jiang | 89e24c1 | 2018-03-22 18:05:44 -0700 | [diff] [blame] | 156 | case ErrorCode::kNoUpdate: | 
|  | 157 | return "ErrorCode::kNoUpdate"; | 
| Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 158 | case ErrorCode::kRollbackNotPossible: | 
|  | 159 | return "ErrorCode::kRollbackNotPossible"; | 
| Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 160 | case ErrorCode::kFirstActiveOmahaPingSentPersistenceError: | 
|  | 161 | return "ErrorCode::kFirstActiveOmahaPingSentPersistenceError"; | 
| Sen Jiang | 57f9180 | 2017-11-14 17:42:13 -0800 | [diff] [blame] | 162 | case ErrorCode::kVerityCalculationError: | 
|  | 163 | return "ErrorCode::kVerityCalculationError"; | 
| Amin Hassani | d3d8421 | 2019-08-17 00:27:44 -0700 | [diff] [blame] | 164 | case ErrorCode::kInternalLibCurlError: | 
|  | 165 | return "ErrorCode::kInternalLibCurlError"; | 
|  | 166 | case ErrorCode::kUnresolvedHostError: | 
|  | 167 | return "ErrorCode::kUnresolvedHostError"; | 
|  | 168 | case ErrorCode::kUnresolvedHostRecovered: | 
|  | 169 | return "ErrorCode::kUnresolvedHostRecovered"; | 
| Yifan Hong | 46e37d4 | 2019-12-13 12:01:42 -0800 | [diff] [blame] | 170 | case ErrorCode::kNotEnoughSpace: | 
|  | 171 | return "ErrorCode::kNotEnoughSpace"; | 
| Yifan Hong | 7727990 | 2019-12-17 16:38:21 -0800 | [diff] [blame] | 172 | case ErrorCode::kDeviceCorrupted: | 
|  | 173 | return "ErrorCode::kDeviceCorrupted"; | 
| Jae Hoon Kim | 3e69b4c | 2020-06-16 09:23:39 -0700 | [diff] [blame] | 174 | case ErrorCode::kPackageExcludedFromUpdate: | 
|  | 175 | return "ErrorCode::kPackageExcludedFromUpdate"; | 
| Kelvin Zhang | 8b1e0dc | 2020-10-26 12:27:53 -0400 | [diff] [blame] | 176 | case ErrorCode::kPostInstallMountError: | 
|  | 177 | return "ErrorCode::kPostInstallMountError"; | 
| Sen Jiang | fe52282 | 2017-10-31 15:14:11 -0700 | [diff] [blame] | 178 | // Don't add a default case to let the compiler warn about newly added | 
|  | 179 | // error codes which should be added here. | 
| Alex Deymo | e88e9fe | 2016-02-03 16:38:00 -0800 | [diff] [blame] | 180 | } | 
|  | 181 |  | 
| hscham | 00b6aa2 | 2020-02-20 12:32:06 +0900 | [diff] [blame] | 182 | return "Unknown error: " + base::NumberToString(static_cast<unsigned>(code)); | 
| Alex Deymo | e88e9fe | 2016-02-03 16:38:00 -0800 | [diff] [blame] | 183 | } | 
|  | 184 |  | 
|  | 185 | }  // namespace utils | 
|  | 186 | }  // namespace chromeos_update_engine |