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
use std::io;
use std::path::PathBuf;
/// Errors returned by Mojay.
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// A file system operation failed.
#[error("I/O error: {0}")]
Io(#[from] io::Error),
/// Invalid on-disk data that cannot be repaired
/// automatically (unreadable segment header, damaged sealed segment...).
#[error("corrupt data in {path}: {reason}")]
Corrupt {
/// The damaged file.
path: PathBuf,
/// What is wrong with it.
reason: String,
},
/// The requested offset does not exist (yet, or any more) in the partition.
#[error("offset {offset} out of range (available: {start}..{end})")]
OffsetOutOfRange {
/// The requested offset.
offset: u64,
/// First available offset.
start: u64,
/// Last offset that can be requested: reading there returns nothing yet.
end: u64,
},
/// A message whose encoded size exceeds
/// [`MAX_RECORD_SIZE`](crate::MAX_RECORD_SIZE). Nothing was written.
#[error("record too large: {size} bytes (maximum {max})")]
RecordTooLarge {
/// Encoded size of the message.
size: usize,
/// The maximum allowed.
max: usize,
},
/// A message that cannot be encoded (a header name too long, for example).
/// Nothing was written.
#[error("invalid record: {0}")]
InvalidRecord(String),
/// An invalid configuration or argument, with the reason.
#[error("invalid configuration: {0}")]
InvalidConfig(String),
/// A topic with this name already exists.
#[error("topic \"{0}\" already exists")]
TopicExists(String),
/// No topic has this name.
#[error("topic \"{0}\" does not exist")]
UnknownTopic(String),
/// A topic or group name that cannot be used as a directory name.
#[error("invalid name \"{name}\": {reason}")]
InvalidName {
/// The rejected name.
name: String,
/// Why it is rejected.
reason: String,
},
/// A partition number beyond those of the topic.
#[error("partition {partition} does not exist (the topic has {partitions})")]
UnknownPartition {
/// The requested partition.
partition: u32,
/// The number of partitions of the topic: valid ones are `0..partitions`.
partitions: u32,
},
}
/// The result type of Mojay operations.
pub type Result<T, E = Error> = std::result::Result<T, E>;
/// Shorthand to build an [`Error::Corrupt`].
pub(crate) fn corrupt(path: impl Into<PathBuf>, reason: impl Into<String>) -> Error {
Error::Corrupt {
path: path.into(),
reason: reason.into(),
}
}