You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
3.6 KiB
126 lines
3.6 KiB
// This file is part of bsv.
|
|
//
|
|
// bsv is free software: you can redistribute it and/or modify it under the
|
|
// terms of the GNU Affero General Public License as published by the Free
|
|
// Software Foundation, either version 3 of the License, or (at your option)
|
|
// any later version.
|
|
//
|
|
// cdb is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
|
// more details.
|
|
//
|
|
// You should have received a copy of the Affero GNU General Public License
|
|
// along with cdb. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
// use std::path::PathBuf;
|
|
|
|
|
|
/// Result type used through cas-core.
|
|
pub type Result<T> = std::result::Result<T, Box<Error>>;
|
|
|
|
/// Error type used through cas-core.
|
|
#[non_exhaustive]
|
|
#[derive(Debug, PartialEq, Eq, thiserror::Error)]
|
|
pub enum Error {
|
|
// #[error("failed to create repository: {message}")]
|
|
// RepositoryCreationFailed {
|
|
// message: String,
|
|
// source: Option<Box<dyn std::error::Error>>,
|
|
// },
|
|
|
|
// #[error("invalid object id: {message}")]
|
|
// InvalidObjectId {
|
|
// message: String,
|
|
// source: Option<Box<dyn std::error::Error>>,
|
|
// },
|
|
|
|
// #[error("invalid size (got: {size}, expected: {expected})")]
|
|
// InvalidSize {
|
|
// size: usize,
|
|
// expected: usize,
|
|
// },
|
|
|
|
// #[error("non-empty directory ({dir})")]
|
|
// NonEmptyDirectory {
|
|
// dir: PathBuf
|
|
// },
|
|
|
|
// #[error("invalid character(s) ({characters})")]
|
|
// InvalidCharacters {
|
|
// characters: String,
|
|
// },
|
|
|
|
// #[error("invalid object type ({otype:?})")]
|
|
// InvalidObjectType {
|
|
// otype: [u8; 4],
|
|
// },
|
|
|
|
// #[error("invalid object size (expected {expected}, got {size})")]
|
|
// InvalidObjectSize {
|
|
// size: u64,
|
|
// expected: u64,
|
|
// },
|
|
|
|
// #[error("unsupported file type")]
|
|
// UnsupportedFileType,
|
|
|
|
// #[error("invalid path ({path})")]
|
|
// InvalidPath { path: PathBuf },
|
|
|
|
// #[error("io error{}", format_optional_path(path))]
|
|
// IoError {
|
|
// source: std::io::Error,
|
|
// path: Option<PathBuf>,
|
|
// },
|
|
|
|
#[error("{0}")]
|
|
Error(String),
|
|
}
|
|
|
|
impl Error {
|
|
// pub fn repository_creation_failed<M: Into<String>>(message: M) -> Box<Error> {
|
|
// Box::new(Error::RepositoryCreationFailed {
|
|
// message: message.into(),
|
|
// source: None,
|
|
// })
|
|
// }
|
|
|
|
// pub fn repository_creation_failed_from<M: Into<String>>(source: Box<dyn std::error::Error>, message: M) -> Box<Error> {
|
|
// Box::new(Error::RepositoryCreationFailed {
|
|
// message: message.into(),
|
|
// source: Some(source),
|
|
// })
|
|
// }
|
|
|
|
// pub fn invalid_object_id<M: Into<String>>(message: M) -> Box<Error> {
|
|
// Box::new(Error::InvalidObjectId {
|
|
// message: message.into(),
|
|
// source: None,
|
|
// })
|
|
// }
|
|
|
|
// pub fn invalid_object_id_from<M: Into<String>>(source: Box<dyn std::error::Error>, message: M) -> Box<Error> {
|
|
// Box::new(Error::InvalidObjectId {
|
|
// message: message.into(),
|
|
// source: Some(source),
|
|
// })
|
|
// }
|
|
|
|
pub fn error<M: Into<String>>(message: M) -> Box<Error> {
|
|
Box::new(Error::Error(message.into()))
|
|
}
|
|
|
|
pub fn err<M: Into<String>, T>(message: M) -> Result<T> {
|
|
Err(Self::error(message))
|
|
}
|
|
}
|
|
|
|
|
|
// fn format_optional_path(maybe_path: &Option<PathBuf>) -> String {
|
|
// match maybe_path {
|
|
// Some(path) => { format!(" ({:?})", path) },
|
|
// None => { String::new() }
|
|
// }
|
|
// }
|
|
|