1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use flv_util::string_helper::upper_cammel_case_to_sentence;
use crate::derive::Encode;
use crate::derive::Decode;
#[fluvio(encode_discriminant)]
#[repr(i16)]
#[derive(Encode, Decode, PartialEq, Debug, Clone, Copy)]
pub enum ErrorCode {
UnknownServerError = -1,
None = 0,
OffsetOutOfRange = 1,
NotLeaderForPartition = 6,
PermissionDenied = 13,
StorageError = 56,
SpuError = 1000,
SpuRegisterationFailed = 1001,
SpuOffline = 1002,
SpuNotFound = 1003,
SpuAlreadyExists = 1004,
TopicError = 2000,
TopicNotFound = 2001,
TopicAlreadyExists = 2002,
TopicPendingInitialization = 2003,
TopicInvalidConfiguration = 2004,
TopicNotProvisioned = 2005,
PartitionPendingInitialization = 3000,
PartitionNotLeader = 3001,
}
impl Default for ErrorCode {
fn default() -> ErrorCode {
ErrorCode::None
}
}
impl ErrorCode {
pub fn is_ok(&self) -> bool {
matches!(self, ErrorCode::None)
}
pub fn to_sentence(&self) -> String {
match self {
ErrorCode::None => "".to_owned(),
_ => upper_cammel_case_to_sentence(format!("{:?}", self), true),
}
}
pub fn is_error(&self) -> bool {
!self.is_ok()
}
}
#[cfg(test)]
mod test {
use std::convert::TryInto;
use super::ErrorCode;
#[test]
fn test_error_code_from_conversion() {
let erro_code: ErrorCode = (1001i16).try_into().expect("convert");
assert_eq!(erro_code, ErrorCode::SpuRegisterationFailed);
}
}