diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-02-03 09:11:49 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-02-04 09:14:01 +0200 |
commit | a2adcb5a90c15b473a2fcf114555443fba8a20ce (patch) | |
tree | 7ec36f244daa105b0da774d6705ef736f9135f64 /src/error.rs | |
parent | bf08ea67ca035fc0e78364450599cefff7cd9bc6 (diff) | |
download | obnam2-a2adcb5a90c15b473a2fcf114555443fba8a20ce.tar.gz |
refactor: have per-module error enums
This means that a function that parses step bindings can't return an
error that the document is missing a title. Such an error return would
be nonsensical, and we use the Rust type system to prevent it, at a
small cost of being a bit verbose.
Additional benefit is that the library portion of Obnam doesn't return
anyhow::Result values anymore.
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/src/error.rs b/src/error.rs index d368763..cf286db 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,25 +1,43 @@ -use crate::chunkid::ChunkId; -use std::path::PathBuf; +use crate::backup_run::BackupError; +use crate::client::{ClientConfigError, ClientError}; +use crate::cmd::restore::RestoreError; +use crate::generation::{LocalGenerationError, NascentError}; +use crate::genlist::GenerationListError; +use std::time::SystemTimeError; +use tempfile::PersistError; use thiserror::Error; -/// Define all the kinds of errors any part of this crate can return. +/// Define all the kinds of errors that functions corresponding to +/// subcommands of the main program can return. #[derive(Debug, Error)] pub enum ObnamError { - #[error("Can't find backup '{0}'")] - UnknownGeneration(String), + #[error(transparent)] + GenerationListError(#[from] GenerationListError), - #[error("Generation has more than one file with the name {0}")] - TooManyFiles(PathBuf), + #[error(transparent)] + ClientError(#[from] ClientError), - #[error("Server response did not have a 'chunk-meta' header for chunk {0}")] - NoChunkMeta(ChunkId), + #[error(transparent)] + ClientConfigError(#[from] ClientConfigError), - #[error("Wrong checksum for chunk {0}, got {1}, expected {2}")] - WrongChecksum(ChunkId, String, String), + #[error(transparent)] + BackupError(#[from] BackupError), - #[error("Chunk is missing: {0}")] - MissingChunk(ChunkId), + #[error(transparent)] + NascentError(#[from] NascentError), - #[error("Chunk is in store too many times: {0}")] - DuplicateChunk(ChunkId), + #[error(transparent)] + LocalGenerationError(#[from] LocalGenerationError), + + #[error(transparent)] + RestoreError(#[from] RestoreError), + + #[error(transparent)] + PersistError(#[from] PersistError), + + #[error(transparent)] + IoError(#[from] std::io::Error), + + #[error(transparent)] + SystemTimeError(#[from] SystemTimeError), } |