mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Support multiple exit codes
..with more specific error enums.
This commit is contained in:
parent
2345a57940
commit
bb7130f960
23 changed files with 112 additions and 34 deletions
|
@ -1,6 +1,9 @@
|
|||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error, Eq, PartialEq, Clone)]
|
||||
#[non_exhaustive]
|
||||
/// Errors returned from taskchampion operations
|
||||
pub enum Error {
|
||||
#[error("Task Database Error: {}", _0)]
|
||||
DbError(String),
|
||||
#[error("Task Database Error: {0}")]
|
||||
Database(String),
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ mod taskdb;
|
|||
mod utils;
|
||||
mod workingset;
|
||||
|
||||
pub use errors::Error;
|
||||
pub use replica::Replica;
|
||||
pub use server::{Server, ServerConfig};
|
||||
pub use storage::StorageConfig;
|
||||
|
|
|
@ -113,7 +113,7 @@ impl Replica {
|
|||
// check that it already exists; this is a convenience check, as the task may already exist
|
||||
// when this Create operation is finally sync'd with operations from other replicas
|
||||
if self.taskdb.get_task(uuid)?.is_none() {
|
||||
return Err(Error::DbError(format!("Task {} does not exist", uuid)).into());
|
||||
return Err(Error::Database(format!("Task {} does not exist", uuid)).into());
|
||||
}
|
||||
self.taskdb.apply(Operation::Delete { uuid })?;
|
||||
trace!("task {} deleted", uuid);
|
||||
|
|
|
@ -49,12 +49,12 @@ impl TaskDb {
|
|||
Operation::Create { uuid } => {
|
||||
// insert if the task does not already exist
|
||||
if !txn.create_task(*uuid)? {
|
||||
return Err(Error::DbError(format!("Task {} already exists", uuid)).into());
|
||||
return Err(Error::Database(format!("Task {} already exists", uuid)).into());
|
||||
}
|
||||
}
|
||||
Operation::Delete { ref uuid } => {
|
||||
if !txn.delete_task(*uuid)? {
|
||||
return Err(Error::DbError(format!("Task {} does not exist", uuid)).into());
|
||||
return Err(Error::Database(format!("Task {} does not exist", uuid)).into());
|
||||
}
|
||||
}
|
||||
Operation::Update {
|
||||
|
@ -71,7 +71,7 @@ impl TaskDb {
|
|||
};
|
||||
txn.set_task(*uuid, task)?;
|
||||
} else {
|
||||
return Err(Error::DbError(format!("Task {} does not exist", uuid)).into());
|
||||
return Err(Error::Database(format!("Task {} does not exist", uuid)).into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue