Debian Codegraph @

third_party/rust/rkv/src/error.rs

raw
1 // Copyright 2018-2019 Mozilla
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 // this file except in compliance with the License. You may obtain a copy of the
5 // License at http://www.apache.org/licenses/LICENSE-2.0
6 // Unless required by applicable law or agreed to in writing, software distributed
7 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8 // CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 // specific language governing permissions and limitations under the License.
10
11 use std::{io, path::PathBuf, sync, thread, thread::ThreadId};
12
13 use thiserror::Error;
14
15 pub use crate::backend::SafeModeError;
16 use crate::value::Type;
17
18 #[derive(Debug, Error)]
19 pub enum DataError {
20 #[error("unknown type tag: {0}")]
21 UnknownType(u8),
22
23 #[error("unexpected type tag: expected {expected}, got {actual}")]
24 UnexpectedType { expected: Type, actual: Type },
25
26 #[error("empty data; expected tag")]
27 Empty,
28
29 #[error("invalid value for type {value_type}: {err}")]
30 DecodingError {
31 value_type: Type,
32 err: Box<bincode::ErrorKind>,
33 },
34
35 #[error("couldn't encode value: {0}")]
36 EncodingError(#[from] Box<bincode::ErrorKind>),
37
38 #[error("invalid uuid bytes")]
39 InvalidUuid,
40 }
41
42 #[derive(Debug, Error)]
43 pub enum StoreError {
44 #[error("manager poisoned")]
45 ManagerPoisonError,
46
47 #[error("database corrupted")]
48 DatabaseCorrupted,
49
50 #[error("key/value pair not found")]
51 KeyValuePairNotFound,
52
53 #[error("unsupported size of key/DB name/data")]
54 KeyValuePairBadSize,
55
56 #[error("file is not a valid database")]
57 FileInvalid,
58
59 #[error("environment mapsize reached")]
60 MapFull,
61
62 #[error("environment maxdbs reached")]
63 DbsFull,
64
65 #[error("environment maxreaders reached")]
66 ReadersFull,
67
68 #[error("I/O error: {0:?}")]
69 IoError(#[from] io::Error),
70
71 #[error("environment path does not exist or not the right type: {0:?}")]
72 UnsuitableEnvironmentPath(PathBuf),
73
74 #[error("data error: {0:?}")]
75 DataError(#[from] DataError),
76
77 #[cfg(feature = "lmdb")]
78 #[error("lmdb backend error: {0}")]
79 LmdbError(lmdb::Error),
80
81 #[error("safe mode backend error: {0}")]
82 SafeModeError(SafeModeError),
83
84 #[error("read transaction already exists in thread {0:?}")]
85 ReadTransactionAlreadyExists(ThreadId),
86
87 #[error("attempted to open DB during transaction in thread {0:?}")]
88 OpenAttemptedDuringTransaction(ThreadId),
89 }
90
91 impl StoreError {
92 pub fn open_during_transaction() -> StoreError {
93 StoreError::OpenAttemptedDuringTransaction(thread::current().id())
94 }
95
96 pub fn read_transaction_already_exists() -> StoreError {
97 StoreError::ReadTransactionAlreadyExists(thread::current().id())
98 }
99 }
100
101 impl<T> From<sync::PoisonError<T>> for StoreError {
102 fn from(_: sync::PoisonError<T>) -> StoreError {
103 StoreError::ManagerPoisonError
104 }
105 }
106
107 #[derive(Debug, Error)]
108 pub enum CloseError {
109 #[error("manager poisoned")]
110 ManagerPoisonError,
111
112 #[error("close attempted while manager has an environment still open")]
113 EnvironmentStillOpen,
114
115 #[error("close attempted while an environment not known to the manager is still open")]
116 UnknownEnvironmentStillOpen,
117
118 #[error("I/O error: {0:?}")]
119 IoError(#[from] io::Error),
120 }
121
122 impl<T> From<sync::PoisonError<T>> for CloseError {
123 fn from(_: sync::PoisonError<T>) -> CloseError {
124 CloseError::ManagerPoisonError
125 }
126 }
127
128 #[derive(Debug, Error)]
129 pub enum MigrateError {
130 #[error("store error: {0}")]
131 StoreError(#[from] StoreError),
132
133 #[error("close error: {0}")]
134 CloseError(#[from] CloseError),
135
136 #[error("manager poisoned")]
137 ManagerPoisonError,
138
139 #[error("source is empty")]
140 SourceEmpty,
141
142 #[error("destination is not empty")]
143 DestinationNotEmpty,
144 }
145
146 impl<T> From<sync::PoisonError<T>> for MigrateError {
147 fn from(_: sync::PoisonError<T>) -> MigrateError {
148 MigrateError::ManagerPoisonError
149 }
150 }