| 14 | namespace tera { |
| 15 | |
| 16 | class ErrorCode { |
| 17 | public: |
| 18 | enum ErrorCodeType { |
| 19 | kOK = 0, |
| 20 | kNotFound = 1, |
| 21 | kBadParam = 2, |
| 22 | kSystem = 3, |
| 23 | kTimeout = 4, |
| 24 | kBusy = 5, |
| 25 | kNoQuota = 6, |
| 26 | kNoAuth = 7, |
| 27 | kUnknown = 8, |
| 28 | kNotImpl = 9, |
| 29 | kTxnFail = 10, |
| 30 | |
| 31 | kAuthBadParam = 21, |
| 32 | kAuthLoginFailed = 22, |
| 33 | |
| 34 | // only for global transaction error |
| 35 | kGTxnDataTooLarge = 101, |
| 36 | kGTxnNotSupport = 102, |
| 37 | kGTxnSchemaError = 103, |
| 38 | kGTxnOpAfterCommit = 104, |
| 39 | kGTxnPrimaryLost = 105, |
| 40 | kGTxnWriteConflict = 106, |
| 41 | kGTxnLockConflict = 107, |
| 42 | kGTxnOKButAckFailed = 108, |
| 43 | kGTxnOKButNotifyFailed = 109, |
| 44 | kGTxnPrewriteTimeout = 110, |
| 45 | kGTxnPrimaryCommitTimeout = 111, |
| 46 | kGTxnTimestampLost = 112 |
| 47 | // end of global transaction error |
| 48 | }; |
| 49 | |
| 50 | public: |
| 51 | // Returns a string includes type&reason |
| 52 | // Format: "type [kOK], reason [success]" |
| 53 | std::string ToString() const; |
| 54 | |
| 55 | ErrorCodeType GetType() const; |
| 56 | std::string GetReason() const; |
| 57 | |
| 58 | // Internal funcion, do not use |
| 59 | ErrorCode(); |
| 60 | void SetFailed(ErrorCodeType err, const std::string& reason = ""); |
| 61 | |
| 62 | private: |
| 63 | ErrorCodeType err_; |
| 64 | std::string reason_; |
| 65 | }; |
| 66 | |
| 67 | // DEPRECATED. Use error_code.ToString() instead. |
| 68 | const char* strerr(ErrorCode error_code); |