2026-01-28 22:48:33 +01:00
|
|
|
// Allow unused assignments for diagnostic fields - they're used by the macros
|
|
|
|
|
#![allow(unused_assignments)]
|
|
|
|
|
|
|
|
|
|
use miette::Diagnostic;
|
|
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
|
|
/// Versioning error type
|
|
|
|
|
#[derive(Error, Debug, Diagnostic)]
|
|
|
|
|
pub enum VersioningError {
|
|
|
|
|
/// Commit not found
|
|
|
|
|
#[error("Commit not found: {commit_id}")]
|
|
|
|
|
#[diagnostic(
|
|
|
|
|
code(versioning::commit_not_found),
|
|
|
|
|
help("Verify the commit ID is correct and exists in the repository")
|
|
|
|
|
)]
|
2026-01-28 23:17:19 +01:00
|
|
|
CommitNotFound { commit_id: String },
|
2026-01-28 22:48:33 +01:00
|
|
|
|
|
|
|
|
/// Conflict detected
|
|
|
|
|
#[error("Conflict detected: {message}")]
|
|
|
|
|
#[diagnostic(
|
|
|
|
|
code(versioning::conflict),
|
|
|
|
|
help("Resolve the conflict by choosing one side or manually merging the changes")
|
|
|
|
|
)]
|
|
|
|
|
Conflict {
|
|
|
|
|
message: String,
|
|
|
|
|
conflicts: Vec<String>,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/// Invalid operation
|
|
|
|
|
#[error("Invalid operation: {message}")]
|
2026-01-28 23:17:19 +01:00
|
|
|
#[diagnostic(code(versioning::invalid_operation), help("{suggestion}"))]
|
|
|
|
|
InvalidOperation { message: String, suggestion: String },
|
2026-01-28 22:48:33 +01:00
|
|
|
|
|
|
|
|
/// Storage error
|
|
|
|
|
#[error("Storage error: {0}")]
|
|
|
|
|
#[diagnostic(
|
|
|
|
|
code(versioning::storage_error),
|
|
|
|
|
help("Check the underlying storage system")
|
|
|
|
|
)]
|
|
|
|
|
StorageError(#[from] reddwarf_storage::StorageError),
|
|
|
|
|
|
|
|
|
|
/// Core error
|
|
|
|
|
#[error("Core error: {0}")]
|
2026-01-28 23:17:19 +01:00
|
|
|
#[diagnostic(code(versioning::core_error), help("This is an internal error"))]
|
2026-01-28 22:48:33 +01:00
|
|
|
CoreError(#[from] reddwarf_core::ReddwarfError),
|
|
|
|
|
|
|
|
|
|
/// Internal error
|
|
|
|
|
#[error("Internal error: {message}")]
|
|
|
|
|
#[diagnostic(
|
|
|
|
|
code(versioning::internal_error),
|
|
|
|
|
help("This is likely a bug. Please report it with full error details")
|
|
|
|
|
)]
|
2026-01-28 23:17:19 +01:00
|
|
|
InternalError { message: String },
|
2026-01-28 22:48:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Result type for versioning operations
|
|
|
|
|
pub type Result<T> = std::result::Result<T, VersioningError>;
|
|
|
|
|
|
|
|
|
|
impl VersioningError {
|
|
|
|
|
/// Create a CommitNotFound error
|
|
|
|
|
pub fn commit_not_found(commit_id: impl Into<String>) -> Self {
|
|
|
|
|
Self::CommitNotFound {
|
|
|
|
|
commit_id: commit_id.into(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Create a Conflict error
|
|
|
|
|
pub fn conflict(message: impl Into<String>, conflicts: Vec<String>) -> Self {
|
|
|
|
|
Self::Conflict {
|
|
|
|
|
message: message.into(),
|
|
|
|
|
conflicts,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Create an InvalidOperation error
|
|
|
|
|
pub fn invalid_operation(message: impl Into<String>, suggestion: impl Into<String>) -> Self {
|
|
|
|
|
Self::InvalidOperation {
|
|
|
|
|
message: message.into(),
|
|
|
|
|
suggestion: suggestion.into(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Create an InternalError
|
|
|
|
|
pub fn internal_error(message: impl Into<String>) -> Self {
|
|
|
|
|
Self::InternalError {
|
|
|
|
|
message: message.into(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|