bookkeeper_client/client/
errors.rs1use std::fmt::{self, Debug, Display, Formatter};
2
3use static_assertions::assert_impl_all;
4
5use crate::error::Error;
6
7#[derive(Debug, Copy, Clone, PartialEq, Eq)]
9#[non_exhaustive]
10pub enum ErrorKind {
11 BookieNotAvailable,
12 BookieNotEnough,
13 BookieUnexpectedResponse,
14 BookieIoError,
15 BookieBadVersion,
16 BookieReadOnly,
17 BookieTooManyRequests,
18
19 EntryNotExisted,
20 EntryInvalidData,
21
22 InvalidMetadata,
23
24 InvalidEntryId,
25 InvalidLedgerId,
26 InvalidServiceUri,
27
28 LedgerConcurrentClose,
29
30 LedgerFenced,
31 LedgerClosed,
32 LedgerClosing,
33 LedgerExisted,
34 LedgerNotExisted,
35 LedgerForceFailed,
36 LedgerIdOverflow,
37
38 UnauthorizedAccess,
39 UnexpectedError,
40 Timeout,
41 ReadExceedLastAddConfirmed,
42
43 MetaClientError,
44 MetaVersionMismatch,
45 MetaInvalidData,
46 MetaUnexpectedResponse,
47 MetaConcurrentOperation,
48 MetaClusterUninitialized,
49}
50
51impl ErrorKind {
52 fn as_str(&self) -> &'static str {
53 use ErrorKind::*;
54 match *self {
55 BookieNotAvailable => "bookie not available",
56 BookieNotEnough => "no enough bookie available",
57 BookieUnexpectedResponse => "unexpected bookie response",
58 BookieIoError => "bookie io error",
59 BookieBadVersion => "bookie protocol mismatch",
60 BookieReadOnly => "write on readonly bookie",
61 BookieTooManyRequests => "too many requests routed to bookie",
62
63 EntryNotExisted => "entry not existed",
64 EntryInvalidData => "invalid entry data",
65
66 InvalidMetadata => "invalid metadata",
67
68 InvalidEntryId => "invalid entry id",
69 InvalidLedgerId => "invalid ledger id",
70 InvalidServiceUri => "invalid service uri",
71
72 LedgerConcurrentClose => "ledger concurrent close detected",
73
74 LedgerFenced => "ledger fenced",
75 LedgerClosed => "ledger closed",
76 LedgerClosing => "ledger closing",
77 LedgerExisted => "ledger already existed",
78 LedgerNotExisted => "ledger not existed",
79 LedgerForceFailed => "ledger force failed",
80 LedgerIdOverflow => "ledger id overflow",
81
82 UnauthorizedAccess => "unauthorized access",
83 UnexpectedError => "unexpected error",
84 Timeout => "timeouted",
85 ReadExceedLastAddConfirmed => "read exceed last add confirmed entry",
86
87 MetaClientError => "meta store client error",
88 MetaVersionMismatch => "meta version mismatch",
89 MetaInvalidData => "invalid meta data",
90 MetaUnexpectedResponse => "unexpected meta response",
91 MetaConcurrentOperation => "concurrent meta operation",
92 MetaClusterUninitialized => "BookKeeper cluster not initialized",
93 }
94 }
95}
96
97impl Display for ErrorKind {
98 fn fmt(&self, f: &mut Formatter<'_>) -> std::result::Result<(), fmt::Error> {
99 f.write_str(self.as_str())
100 }
101}
102
103impl std::error::Error for ErrorKind {}
104
105assert_impl_all!(ErrorKind: Display, std::error::Error, Send, Sync);
106
107pub type BkError = Error<ErrorKind>;
108pub type BkResult<T> = std::result::Result<T, BkError>;
109pub type Result<T> = std::result::Result<T, BkError>;