// 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 . // use std::path::PathBuf; /// Result type used through cas-core. pub type Result = std::result::Result>; /// 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>, // }, // #[error("invalid object id: {message}")] // InvalidObjectId { // message: String, // source: Option>, // }, // #[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, // }, #[error("{0}")] Error(String), } impl Error { // pub fn repository_creation_failed>(message: M) -> Box { // Box::new(Error::RepositoryCreationFailed { // message: message.into(), // source: None, // }) // } // pub fn repository_creation_failed_from>(source: Box, message: M) -> Box { // Box::new(Error::RepositoryCreationFailed { // message: message.into(), // source: Some(source), // }) // } // pub fn invalid_object_id>(message: M) -> Box { // Box::new(Error::InvalidObjectId { // message: message.into(), // source: None, // }) // } // pub fn invalid_object_id_from>(source: Box, message: M) -> Box { // Box::new(Error::InvalidObjectId { // message: message.into(), // source: Some(source), // }) // } pub fn error>(message: M) -> Box { Box::new(Error::Error(message.into())) } pub fn err, T>(message: M) -> Result { Err(Self::error(message)) } } // fn format_optional_path(maybe_path: &Option) -> String { // match maybe_path { // Some(path) => { format!(" ({:?})", path) }, // None => { String::new() } // } // }