Skip to content

Commit 285cd09

Browse files
committed
re-export proto error
Signed-off-by: Ping Yu <yuping@pingcap.com>
1 parent 5b16922 commit 285cd09

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

src/common/errors.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ use crate::proto::kvrpcpb;
88
use crate::region::RegionVerId;
99
use crate::BoundRange;
1010

11+
/// Protobuf-generated region-level error returned by TiKV.
12+
///
13+
/// This type is generated from TiKV's protobuf definitions and may change in a
14+
/// future release even if the wire format is compatible.
15+
#[doc(inline)]
16+
pub use crate::proto::errorpb::Error as ProtoRegionError;
17+
18+
/// Protobuf-generated per-key error returned by TiKV.
19+
///
20+
/// This type is generated from TiKV's protobuf definitions and may change in a
21+
/// future release even if the wire format is compatible.
22+
#[doc(inline)]
23+
pub use crate::proto::kvrpcpb::KeyError as ProtoKeyError;
24+
1125
/// An error originating from the TiKV client or dependencies.
1226
#[derive(Debug, Error)]
1327
#[allow(clippy::large_enum_variant)]
@@ -63,13 +77,13 @@ pub enum Error {
6377
Canceled(#[from] futures::channel::oneshot::Canceled),
6478
/// Errors caused by changes of region information
6579
#[error("Region error: {0:?}")]
66-
RegionError(Box<crate::proto::errorpb::Error>),
80+
RegionError(Box<ProtoRegionError>),
6781
/// Whether the transaction is committed or not is undetermined
6882
#[error("Whether the transaction is committed or not is undetermined")]
6983
UndeterminedError(Box<Error>),
70-
/// Wraps `crate::proto::kvrpcpb::KeyError`
84+
/// Wraps a per-key error returned by TiKV.
7185
#[error("{0:?}")]
72-
KeyError(Box<crate::proto::kvrpcpb::KeyError>),
86+
KeyError(Box<ProtoKeyError>),
7387
/// Multiple errors generated from the ExtractError plan.
7488
#[error("Multiple errors: {0:?}")]
7589
ExtractedErrors(Vec<Error>),
@@ -116,14 +130,14 @@ pub enum Error {
116130
TxnNotFound(kvrpcpb::TxnNotFound),
117131
}
118132

119-
impl From<crate::proto::errorpb::Error> for Error {
120-
fn from(e: crate::proto::errorpb::Error) -> Error {
133+
impl From<ProtoRegionError> for Error {
134+
fn from(e: ProtoRegionError) -> Error {
121135
Error::RegionError(Box::new(e))
122136
}
123137
}
124138

125-
impl From<crate::proto::kvrpcpb::KeyError> for Error {
126-
fn from(e: crate::proto::kvrpcpb::KeyError) -> Error {
139+
impl From<ProtoKeyError> for Error {
140+
fn from(e: ProtoKeyError) -> Error {
127141
Error::KeyError(Box::new(e))
128142
}
129143
}

src/common/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ mod errors;
44
pub mod security;
55

66
pub use self::errors::Error;
7+
pub use self::errors::ProtoKeyError;
8+
pub use self::errors::ProtoRegionError;
79
pub use self::errors::Result;

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ pub use common::security::SecurityManager;
122122
#[doc(inline)]
123123
pub use common::Error;
124124
#[doc(inline)]
125+
pub use common::ProtoKeyError;
126+
#[doc(inline)]
127+
pub use common::ProtoRegionError;
128+
#[doc(inline)]
125129
pub use common::Result;
126130
#[doc(inline)]
127131
pub use config::Config;
@@ -157,6 +161,8 @@ pub use crate::transaction::CheckLevel;
157161
#[doc(inline)]
158162
pub use crate::transaction::Client as TransactionClient;
159163
#[doc(inline)]
164+
pub use crate::transaction::ProtoLockInfo;
165+
#[doc(inline)]
160166
pub use crate::transaction::Snapshot;
161167
#[doc(inline)]
162168
pub use crate::transaction::Transaction;

src/transaction/client.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ use crate::Backoff;
2828
use crate::BoundRange;
2929
use crate::Result;
3030

31+
/// Protobuf-generated lock information returned by TiKV.
32+
///
33+
/// This type is generated from TiKV's protobuf definitions and may change in a
34+
/// future release even if the wire format is compatible.
3135
#[doc(inline)]
32-
pub use crate::proto::kvrpcpb::LockInfo;
36+
pub use crate::proto::kvrpcpb::LockInfo as ProtoLockInfo;
3337

3438
// FIXME: cargo-culted value
3539
const SCAN_LOCK_BATCH_SIZE: u32 = 1024;
@@ -304,7 +308,7 @@ impl Client {
304308
safepoint: &Timestamp,
305309
range: impl Into<BoundRange>,
306310
batch_size: u32,
307-
) -> Result<Vec<LockInfo>> {
311+
) -> Result<Vec<ProtoLockInfo>> {
308312
use crate::request::TruncateKeyspace;
309313

310314
let range = range.into().encode_keyspace(self.keyspace, KeyMode::Txn);
@@ -323,10 +327,10 @@ impl Client {
323327
/// timestamp when checking transaction status.
324328
pub async fn resolve_locks(
325329
&self,
326-
locks: Vec<LockInfo>,
330+
locks: Vec<ProtoLockInfo>,
327331
timestamp: Timestamp,
328332
mut backoff: Backoff,
329-
) -> Result<Vec<LockInfo>> {
333+
) -> Result<Vec<ProtoLockInfo>> {
330334
use crate::request::TruncateKeyspace;
331335

332336
let mut live_locks = locks;

src/transaction/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! **Warning:** It is not advisable to use both raw and transactional functionality in the same keyspace.
1010
1111
pub use client::Client;
12-
pub use client::LockInfo;
12+
pub use client::ProtoLockInfo;
1313
pub(crate) use lock::resolve_locks;
1414
pub(crate) use lock::HasLocks;
1515
pub use snapshot::Snapshot;

0 commit comments

Comments
 (0)