tikv_client/common/
errors.rs1use std::result;
4
5use thiserror::Error;
6
7use crate::proto::kvrpcpb;
8use crate::BoundRange;
9
10#[derive(Debug, Error)]
12#[allow(clippy::large_enum_variant)]
13pub enum Error {
14 #[error("Unimplemented feature")]
16 Unimplemented,
17 #[error("Duplicate key insertion")]
19 DuplicateKeyInsertion,
20 #[error("Failed to resolve lock")]
22 ResolveLockError(Vec<kvrpcpb::LockInfo>),
23 #[error("Invalid operation for this type of transaction")]
25 InvalidTransactionType,
26 #[error("Cannot read or write data after any attempt to commit or roll back the transaction")]
28 OperationAfterCommitError,
29 #[error("1PC transaction could not be committed.")]
31 OnePcFailure,
32 #[error("transaction has no primary key")]
34 NoPrimaryKey,
35 #[error(
37 "The operation is not supported in current mode, please consider using RawClient with or without atomic mode"
38 )]
39 UnsupportedMode,
40 #[error("There is no current_regions in the EpochNotMatch error")]
41 NoCurrentRegions,
42 #[error("The specified entry is not found in the region cache")]
43 EntryNotFoundInRegionCache,
44 #[error("IO error: {0}")]
46 Io(#[from] std::io::Error),
47 #[error("tokio channel error: {0}")]
49 Channel(#[from] tokio::sync::oneshot::error::RecvError),
50 #[error("gRPC error: {0}")]
52 Grpc(#[from] tonic::transport::Error),
53 #[error("gRPC api error: {0}")]
55 GrpcAPI(#[from] tonic::Status),
56 #[error("url error: {0}")]
58 Url(#[from] tonic::codegen::http::uri::InvalidUri),
59 #[error("A futures oneshot channel was canceled. {0}")]
61 Canceled(#[from] futures::channel::oneshot::Canceled),
62 #[error("Region error: {0:?}")]
64 RegionError(Box<crate::proto::errorpb::Error>),
65 #[error("Whether the transaction is committed or not is undetermined")]
67 UndeterminedError(Box<Error>),
68 #[error("{0:?}")]
70 KeyError(Box<crate::proto::kvrpcpb::KeyError>),
71 #[error("Multiple errors: {0:?}")]
73 ExtractedErrors(Vec<Error>),
74 #[error("Multiple key errors: {0:?}")]
76 MultipleKeyErrors(Vec<Error>),
77 #[error("Unsupported column family {}", _0)]
79 ColumnFamilyError(String),
80 #[error("Failed to join tokio tasks")]
82 JoinError(#[from] tokio::task::JoinError),
83 #[error("Region is not found for key: {:?}", key)]
85 RegionForKeyNotFound { key: Vec<u8> },
86 #[error("Region is not found for range: {:?}", range)]
87 RegionForRangeNotFound { range: BoundRange },
88 #[error("Region {} is not found in the response", region_id)]
90 RegionNotFoundInResponse { region_id: u64 },
91 #[error("Leader of region {} is not found", region_id)]
93 LeaderNotFound { region_id: u64 },
94 #[error("Limit {} exceeds max scan limit {}", limit, max_limit)]
96 MaxScanLimitExceeded { limit: u32, max_limit: u32 },
97 #[error("Invalid Semver string: {0:?}")]
98 InvalidSemver(#[from] semver::Error),
99 #[error("Kv error. {}", message)]
101 KvError { message: String },
102 #[error("{}", message)]
103 InternalError { message: String },
104 #[error("{0}")]
105 StringError(String),
106 #[error("PessimisticLock error: {:?}", inner)]
107 PessimisticLockError {
108 inner: Box<Error>,
109 success_keys: Vec<Vec<u8>>,
110 },
111}
112
113impl From<crate::proto::errorpb::Error> for Error {
114 fn from(e: crate::proto::errorpb::Error) -> Error {
115 Error::RegionError(Box::new(e))
116 }
117}
118
119impl From<crate::proto::kvrpcpb::KeyError> for Error {
120 fn from(e: crate::proto::kvrpcpb::KeyError) -> Error {
121 Error::KeyError(Box::new(e))
122 }
123}
124
125pub type Result<T> = result::Result<T, Error>;
127
128#[doc(hidden)]
129#[macro_export]
130macro_rules! internal_err {
131 ($e:expr) => ({
132 $crate::Error::InternalError {
133 message: format!("[{}:{}]: {}", file!(), line!(), $e)
134 }
135 });
136 ($f:tt, $($arg:expr),+) => ({
137 internal_err!(format!($f, $($arg),+))
138 });
139}