1aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo//
2aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Copyright (C) 2013 The Android Open Source Project
3aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo//
4aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Licensed under the Apache License, Version 2.0 (the "License");
5aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// you may not use this file except in compliance with the License.
6aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// You may obtain a copy of the License at
7aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo//
8aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo//      http://www.apache.org/licenses/LICENSE-2.0
9aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo//
10aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// Unless required by applicable law or agreed to in writing, software
11aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// distributed under the License is distributed on an "AS IS" BASIS,
12aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// See the License for the specific language governing permissions and
14aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo// limitations under the License.
15aea4c1cea20dda7ae7e85fc8924a2d784f70d806Alex Deymo//
16a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
1739910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#ifndef UPDATE_ENGINE_COMMON_ERROR_CODE_H_
1839910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#define UPDATE_ENGINE_COMMON_ERROR_CODE_H_
19a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
20d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6Alex Vakulenko#include <ostream>  // NOLINT(readability/streams)
21d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold
22a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthennamespace chromeos_update_engine {
23a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
24a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen// Action exit codes.
25d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnoldenum class ErrorCode : int {
26d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kSuccess = 0,
27d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kError = 1,
28d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kOmahaRequestError = 2,
29d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kOmahaResponseHandlerError = 3,
30d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kFilesystemCopierError = 4,
31d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kPostinstallRunnerError = 5,
32d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kPayloadMismatchedType = 6,
33d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kInstallDeviceOpenError = 7,
34d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kKernelDeviceOpenError = 8,
35d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadTransferError = 9,
36d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kPayloadHashMismatchError = 10,
37d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kPayloadSizeMismatchError = 11,
38d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadPayloadVerificationError = 12,
39d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadNewPartitionInfoError = 13,
40d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadWriteError = 14,
41d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kNewRootfsVerificationError = 15,
42d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kNewKernelVerificationError = 16,
43d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kSignedDeltaPayloadExpectedError = 17,
44d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadPayloadPubKeyVerificationError = 18,
45d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kPostinstallBootedFromFirmwareB = 19,
46d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadStateInitializationError = 20,
47d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadInvalidMetadataMagicString = 21,
48d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadSignatureMissingInManifest = 22,
49d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadManifestParseError = 23,
50d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadMetadataSignatureError = 24,
51d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadMetadataSignatureVerificationError = 25,
52d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadMetadataSignatureMismatch = 26,
53d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadOperationHashVerificationError = 27,
54d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadOperationExecutionError = 28,
55d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadOperationHashMismatch = 29,
56d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kOmahaRequestEmptyResponseError = 30,
57d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kOmahaRequestXMLParseError = 31,
58d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadInvalidMetadataSize = 32,
59d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadInvalidMetadataSignature = 33,
60d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kOmahaResponseInvalid = 34,
61d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kOmahaUpdateIgnoredPerPolicy = 35,
62d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kOmahaUpdateDeferredPerPolicy = 36,
63d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kOmahaErrorInHTTPResponse = 37,
64d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadOperationHashMissingError = 38,
65d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDownloadMetadataSignatureMissingError = 39,
66d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kOmahaUpdateDeferredForBackoff = 40,
67d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kPostinstallPowerwashError = 41,
68d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kUpdateCanceledByChannelChange = 42,
69d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kPostinstallFirmwareRONotUpdatable = 43,
70d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kUnsupportedMajorPayloadVersion = 44,
71d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kUnsupportedMinorPayloadVersion = 45,
72f3e2801f18bae14e41099e007de7c9a019735556David Zeuthen  kOmahaRequestXMLHasEntityDecl = 46,
73eb9e6d8d8813b2d5a81a14e0184f7b4798573606Allie Wood  kFilesystemVerifierError = 47,
741f19dccb115cf608104b1cb0d192a53ae32f238fAlex Deymo  kUserCanceled = 48,
752494e28b88a819618c6325a5b081ef7de28549eeKevin Cernekee  kNonCriticalUpdateInOOBE = 49,
765ed4f4c5b198066feefc4fd49107affa89dc559aSen Jiang  // kOmahaUpdateIgnoredOverCellular = 50,
775ed4f4c5b198066feefc4fd49107affa89dc559aSen Jiang  kPayloadTimestampError = 51,
78a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
794d039449ae2b9a218660d6ac92d610f50b308837Don Garrett  // VERY IMPORTANT! When adding new error codes:
804d039449ae2b9a218660d6ac92d610f50b308837Don Garrett  //
814d039449ae2b9a218660d6ac92d610f50b308837Don Garrett  // 1) Update tools/metrics/histograms/histograms.xml in Chrome.
824d039449ae2b9a218660d6ac92d610f50b308837Don Garrett  //
834d039449ae2b9a218660d6ac92d610f50b308837Don Garrett  // 2) Update the assorted switch statements in update_engine which won't
844d039449ae2b9a218660d6ac92d610f50b308837Don Garrett  //    build until this case is added.
85a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
86a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // Any code above this is sent to both Omaha and UMA as-is, except
87d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  // kOmahaErrorInHTTPResponse (see error code 2000 for more details).
88a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // Codes/flags below this line is sent only to Omaha and not to UMA.
89a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
90d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  // kUmaReportedMax is not an error code per se, it's just the count
91a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // of the number of enums above.  Add any new errors above this line if you
92a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // want them to show up on UMA. Stuff below this line will not be sent to UMA
93a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // but is used for other errors that are sent to Omaha. We don't assign any
94a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // particular value for this enum so that it's just one more than the last
95a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // one above and thus always represents the correct count of UMA metrics
96a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // buckets, even when new enums are added above this line in future. See
97af9a863cd7aa4aa4ef12227908a10bc07440a0f0Alex Deymo  // metrics::ReportUpdateAttemptMetrics() on how this enum is used.
98d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kUmaReportedMax,
99a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
100a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // use the 2xxx range to encode HTTP errors. These errors are available in
101a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // Dremel with the individual granularity. But for UMA purposes, all these
102d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  // errors are aggregated into one: kOmahaErrorInHTTPResponse.
103d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kOmahaRequestHTTPResponseBase = 2000,  // + HTTP response code
104a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
105a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // TODO(jaysri): Move out all the bit masks into separate constants
106a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // outside the enum as part of fixing bug 34369.
107a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // Bit flags. Remember to update the mask below for new bits.
108a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
109a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // Set if boot mode not normal.
110d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  // TODO(garnold) This is very debatable value to use, knowing that the
111d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  // underlying type is a signed int (often, 32-bit). However, at this point
112d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  // there are parts of the ecosystem that expect this to be a negative value,
113d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  // so we preserve this semantics. This should be reconsidered if/when we
114d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  // modify the implementation of ErrorCode into a properly encapsulated class.
115d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kDevModeFlag = 1 << 31,
116a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
117a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // Set if resuming an interruped update.
118d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kResumedFlag = 1 << 30,
119a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
120a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // Set if using a dev/test image as opposed to an MP-signed image.
121d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kTestImageFlag = 1 << 29,
122a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
123a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // Set if using devserver or Omaha sandbox (using crosh autest).
124d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  kTestOmahaUrlFlag = 1 << 28,
125a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
126a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // Mask that indicates bit positions that are used to indicate special flags
127a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // that are embedded in the error code to provide additional context about
128a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen  // the system in which the error was encountered.
1291f19dccb115cf608104b1cb0d192a53ae32f238fAlex Deymo  kSpecialFlags =
1301f19dccb115cf608104b1cb0d192a53ae32f238fAlex Deymo      (kDevModeFlag | kResumedFlag | kTestImageFlag | kTestOmahaUrlFlag)
131a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen};
132a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
133d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnoldinline std::ostream& operator<<(std::ostream& os, ErrorCode val) {
134d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold  return os << static_cast<int>(val);
135d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold}
136d1c4d2dd3daed1d507038046c0355fbafb85260cGilad Arnold
137a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen}  // namespace chromeos_update_engine
138a99981fda75fe0b17e96c700e3ddc93eca1cebe5David Zeuthen
13939910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#endif  // UPDATE_ENGINE_COMMON_ERROR_CODE_H_
140