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)26string 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>(static_cast<int>(code) & 34 ~static_cast<int>(ErrorCode::kSpecialFlags)); 35 switch (code) { 36 case ErrorCode::kSuccess: 37 return "ErrorCode::kSuccess"; 38 case ErrorCode::kError: 39 return "ErrorCode::kError"; 40 case ErrorCode::kOmahaRequestError: 41 return "ErrorCode::kOmahaRequestError"; 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"; 148 case ErrorCode::kNonCriticalUpdateInOOBE: 149 return "ErrorCode::kNonCriticalUpdateInOOBE"; 150 case ErrorCode::kOmahaUpdateIgnoredOverCellular: 151 return "ErrorCode::kOmahaUpdateIgnoredOverCellular"; 152 case ErrorCode::kPayloadTimestampError: 153 return "ErrorCode::kPayloadTimestampError"; 154 case ErrorCode::kUpdatedButNotActive: 155 return "ErrorCode::kUpdatedButNotActive"; 156 case ErrorCode::kNoUpdate: 157 return "ErrorCode::kNoUpdate"; 158 case ErrorCode::kRollbackNotPossible: 159 return "ErrorCode::kRollbackNotPossible"; 160 case ErrorCode::kFirstActiveOmahaPingSentPersistenceError: 161 return "ErrorCode::kFirstActiveOmahaPingSentPersistenceError"; 162 case ErrorCode::kVerityCalculationError: 163 return "ErrorCode::kVerityCalculationError"; 164 case ErrorCode::kInternalLibCurlError: 165 return "ErrorCode::kInternalLibCurlError"; 166 case ErrorCode::kUnresolvedHostError: 167 return "ErrorCode::kUnresolvedHostError"; 168 case ErrorCode::kUnresolvedHostRecovered: 169 return "ErrorCode::kUnresolvedHostRecovered"; 170 case ErrorCode::kNotEnoughSpace: 171 return "ErrorCode::kNotEnoughSpace"; 172 case ErrorCode::kDeviceCorrupted: 173 return "ErrorCode::kDeviceCorrupted"; 174 case ErrorCode::kPackageExcludedFromUpdate: 175 return "ErrorCode::kPackageExcludedFromUpdate"; 176 case ErrorCode::kPostInstallMountError: 177 return "ErrorCode::kPostInstallMountError"; 178 // Don't add a default case to let the compiler warn about newly added 179 // error codes which should be added here. 180 } 181 182 return "Unknown error: " + base::NumberToString(static_cast<unsigned>(code)); 183 } 184 185 } // namespace utils 186 } // namespace chromeos_update_engine 187