Debian Codegraph @

third_party/rust/rkv/src/backend/impl_lmdb/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::{fmt, io, path::PathBuf};
12
13 use crate::{backend::traits::BackendError, error::StoreError};
14
15 #[derive(Debug)]
16 pub enum ErrorImpl {
17 LmdbError(lmdb::Error),
18 UnsuitableEnvironmentPath(PathBuf),
19 IoError(io::Error),
20 }
21
22 impl BackendError for ErrorImpl {}
23
24 impl fmt::Display for ErrorImpl {
25 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
26 match self {
27 ErrorImpl::LmdbError(e) => e.fmt(fmt),
28 ErrorImpl::UnsuitableEnvironmentPath(_) => write!(fmt, "UnsuitableEnvironmentPath"),
29 ErrorImpl::IoError(e) => e.fmt(fmt),
30 }
31 }
32 }
33
34 impl Into<StoreError> for ErrorImpl {
35 fn into(self) -> StoreError {
36 match self {
37 ErrorImpl::LmdbError(lmdb::Error::Corrupted) => StoreError::DatabaseCorrupted,
38 ErrorImpl::LmdbError(lmdb::Error::NotFound) => StoreError::KeyValuePairNotFound,
39 ErrorImpl::LmdbError(lmdb::Error::BadValSize) => StoreError::KeyValuePairBadSize,
40 ErrorImpl::LmdbError(lmdb::Error::Invalid) => StoreError::FileInvalid,
41 ErrorImpl::LmdbError(lmdb::Error::MapFull) => StoreError::MapFull,
42 ErrorImpl::LmdbError(lmdb::Error::DbsFull) => StoreError::DbsFull,
43 ErrorImpl::LmdbError(lmdb::Error::ReadersFull) => StoreError::ReadersFull,
44 ErrorImpl::LmdbError(error) => StoreError::LmdbError(error),
45 ErrorImpl::UnsuitableEnvironmentPath(path) => {
46 StoreError::UnsuitableEnvironmentPath(path)
47 }
48 ErrorImpl::IoError(error) => StoreError::IoError(error),
49 }
50 }
51 }
52
53 impl From<io::Error> for ErrorImpl {
54 fn from(e: io::Error) -> ErrorImpl {
55 ErrorImpl::IoError(e)
56 }
57 }