refactor(core): Rename GiError to LoreError and add search infrastructure
Mechanical rename of GiError -> LoreError across the core module to match the project's rebranding from gitlab-inbox to gitlore/lore. Updates the error enum name, all From impls, and the Result type alias. Additionally introduces: - New error variants for embedding pipeline: OllamaUnavailable, OllamaModelNotFound, EmbeddingFailed, EmbeddingsNotBuilt. Each includes actionable suggestions (e.g., "ollama serve", "ollama pull nomic-embed-text") to guide users through recovery. - New error codes 14-16 for programmatic handling of Ollama failures. - Savepoint-based migration execution in db.rs: each migration now runs inside a SQLite SAVEPOINT so a failed migration rolls back cleanly without corrupting the schema_version tracking. Previously a partial migration could leave the database in an inconsistent state. - core::backoff module: exponential backoff with jitter utility for retry loops in the embedding pipeline and discussion queues. - core::project module: helper for resolving project IDs and paths from the local database, used by the document regenerator and search filters. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,9 @@ pub enum ErrorCode {
|
||||
TransformError,
|
||||
IoError,
|
||||
InternalError,
|
||||
OllamaUnavailable,
|
||||
OllamaModelNotFound,
|
||||
EmbeddingFailed,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ErrorCode {
|
||||
@@ -39,6 +42,9 @@ impl std::fmt::Display for ErrorCode {
|
||||
Self::TransformError => "TRANSFORM_ERROR",
|
||||
Self::IoError => "IO_ERROR",
|
||||
Self::InternalError => "INTERNAL_ERROR",
|
||||
Self::OllamaUnavailable => "OLLAMA_UNAVAILABLE",
|
||||
Self::OllamaModelNotFound => "OLLAMA_MODEL_NOT_FOUND",
|
||||
Self::EmbeddingFailed => "EMBEDDING_FAILED",
|
||||
};
|
||||
write!(f, "{code}")
|
||||
}
|
||||
@@ -61,13 +67,16 @@ impl ErrorCode {
|
||||
Self::MigrationFailed => 11,
|
||||
Self::IoError => 12,
|
||||
Self::TransformError => 13,
|
||||
Self::OllamaUnavailable => 14,
|
||||
Self::OllamaModelNotFound => 15,
|
||||
Self::EmbeddingFailed => 16,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Main error type for gitlore.
|
||||
#[derive(Error, Debug)]
|
||||
pub enum GiError {
|
||||
pub enum LoreError {
|
||||
#[error("Config file not found at {path}. Run \"lore init\" first.")]
|
||||
ConfigNotFound { path: String },
|
||||
|
||||
@@ -129,9 +138,25 @@ pub enum GiError {
|
||||
|
||||
#[error("{0}")]
|
||||
Other(String),
|
||||
|
||||
#[error("Cannot connect to Ollama at {base_url}. Is it running?")]
|
||||
OllamaUnavailable {
|
||||
base_url: String,
|
||||
#[source]
|
||||
source: Option<reqwest::Error>,
|
||||
},
|
||||
|
||||
#[error("Ollama model '{model}' not found. Run: ollama pull {model}")]
|
||||
OllamaModelNotFound { model: String },
|
||||
|
||||
#[error("Embedding failed for document {document_id}: {reason}")]
|
||||
EmbeddingFailed { document_id: i64, reason: String },
|
||||
|
||||
#[error("No embeddings found. Run: lore embed")]
|
||||
EmbeddingsNotBuilt,
|
||||
}
|
||||
|
||||
impl GiError {
|
||||
impl LoreError {
|
||||
/// Get the error code for programmatic handling.
|
||||
pub fn code(&self) -> ErrorCode {
|
||||
match self {
|
||||
@@ -152,6 +177,10 @@ impl GiError {
|
||||
Self::NotFound(_) => ErrorCode::GitLabNotFound,
|
||||
Self::Ambiguous(_) => ErrorCode::GitLabNotFound,
|
||||
Self::Other(_) => ErrorCode::InternalError,
|
||||
Self::OllamaUnavailable { .. } => ErrorCode::OllamaUnavailable,
|
||||
Self::OllamaModelNotFound { .. } => ErrorCode::OllamaModelNotFound,
|
||||
Self::EmbeddingFailed { .. } => ErrorCode::EmbeddingFailed,
|
||||
Self::EmbeddingsNotBuilt => ErrorCode::EmbeddingFailed,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +222,15 @@ impl GiError {
|
||||
Self::Ambiguous(_) => Some(
|
||||
"Use -p to choose a specific project.\n\n Example:\n lore issues 42 -p group/project-a\n lore mrs 99 -p group/project-b",
|
||||
),
|
||||
_ => None,
|
||||
Self::OllamaUnavailable { .. } => Some("Start Ollama: ollama serve"),
|
||||
Self::OllamaModelNotFound { .. } => {
|
||||
Some("Pull the model: ollama pull nomic-embed-text")
|
||||
}
|
||||
Self::EmbeddingFailed { .. } => {
|
||||
Some("Check Ollama logs or retry with 'lore embed --retry-failed'")
|
||||
}
|
||||
Self::EmbeddingsNotBuilt => Some("Generate embeddings first: lore embed"),
|
||||
Self::Json(_) | Self::Io(_) | Self::Transform(_) | Self::Other(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,12 +264,12 @@ pub struct RobotErrorOutput {
|
||||
pub error: RobotError,
|
||||
}
|
||||
|
||||
impl From<&GiError> for RobotErrorOutput {
|
||||
fn from(e: &GiError) -> Self {
|
||||
impl From<&LoreError> for RobotErrorOutput {
|
||||
fn from(e: &LoreError) -> Self {
|
||||
Self {
|
||||
error: e.to_robot_error(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, GiError>;
|
||||
pub type Result<T> = std::result::Result<T, LoreError>;
|
||||
|
||||
Reference in New Issue
Block a user