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::{ 12 io, 13 num, 14 str, 15 }; 16 17 use thiserror::Error; 18 19 #[derive(Debug, Error)] 20 pub enum MigrateError { 21 #[error("database not found: {0:?}")] 22 DatabaseNotFound(String), 23 24 #[error("{0}")] 25 FromString(String), 26 27 #[error("couldn't determine bit depth")] 28 IndeterminateBitDepth, 29 30 #[error("I/O error: {0:?}")] 31 IoError(#[from] io::Error), 32 33 #[error("invalid DatabaseFlags bits")] 34 InvalidDatabaseBits, 35 36 #[error("invalid data version")] 37 InvalidDataVersion, 38 39 #[error("invalid magic number")] 40 InvalidMagicNum, 41 42 #[error("invalid NodeFlags bits")] 43 InvalidNodeBits, 44 45 #[error("invalid PageFlags bits")] 46 InvalidPageBits, 47 48 #[error("invalid page number")] 49 InvalidPageNum, 50 51 #[error("lmdb backend error: {0}")] 52 LmdbError(#[from] lmdb::Error), 53 54 #[error("string conversion error")] 55 StringConversionError, 56 57 #[error("TryFromInt error: {0:?}")] 58 TryFromIntError(#[from] num::TryFromIntError), 59 60 #[error("unexpected Page variant")] 61 UnexpectedPageVariant, 62 63 #[error("unexpected PageHeader variant")] 64 UnexpectedPageHeaderVariant, 65 66 #[error("unsupported PageHeader variant")] 67 UnsupportedPageHeaderVariant, 68 69 #[error("UTF8 error: {0:?}")] 70 Utf8Error(#[from] str::Utf8Error), 71 } 72 73 impl From<&str> for MigrateError { from(e: &str) -> MigrateError74 fn from(e: &str) -> MigrateError { 75 MigrateError::FromString(e.to_string()) 76 } 77 } 78 79 impl From<String> for MigrateError { from(e: String) -> MigrateError80 fn from(e: String) -> MigrateError { 81 MigrateError::FromString(e) 82 } 83 } 84