diff --git a/src/error.rs b/src/error.rs index 32910d9..f86ea77 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,3 +1,5 @@ +use crate::commit::types::{CommitMessageError, DescriptionError, ScopeError}; + #[derive(Debug, thiserror::Error)] pub enum Error { // Domain errors @@ -5,16 +7,36 @@ pub enum Error { InvalidScope(String), #[error("Invalid description: {0}")] InvalidDescription(String), + #[error("Invalid commit message: {0}")] + InvalidCommitMessage(String), // Infrastructure errors #[error("Not a Jujutsu repository")] NotARepository, - #[error("jj is not installed or not in PATH")] - JjNotFound, - #[error("jj command failed: {message}")] - JjCommand { message: String, stderr: String }, + #[error("Repository operation failed: {context}")] + JjOperation { context: String }, + #[error("Repository is locked by another process")] + RepositoryLocked, // Application errors #[error("Operation cancelled by user")] Cancelled, #[error("Non-interactive terminal detected")] NonInteractive, } + +impl From for Error { + fn from(value: ScopeError) -> Self { + Self::InvalidScope(value.to_string()) + } +} + +impl From for Error { + fn from(value: DescriptionError) -> Self { + Self::InvalidDescription(value.to_string()) + } +} + +impl From for Error { + fn from(value: CommitMessageError) -> Self { + Self::InvalidCommitMessage(value.to_string()) + } +}