git_indexer/
error.rs

1//! Error types for the git-indexer crate.
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// Result type alias using the crate's Error type.
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// Main error type for the git-indexer crate.
10#[derive(Error, Debug)]
11pub enum Error {
12    /// Error during git repository operations.
13    #[error("Git error: {0}")]
14    Git(#[from] GitError),
15
16    /// Error during Helix DB operations.
17    #[error("Helix DB error: {0}")]
18    Helix(#[from] HelixError),
19
20    /// Error during client configuration.
21    #[error("Configuration error: {0}")]
22    Config(#[from] ConfigError),
23
24    /// JSON serialization/deserialization error.
25    #[error("JSON error: {0}")]
26    Json(#[from] serde_json::Error),
27}
28
29/// Errors related to git repository operations.
30#[derive(Error, Debug)]
31pub enum GitError {
32    /// Failed to discover or open a git repository.
33    #[error("Failed to discover git repository at {path}: {message}")]
34    RepositoryNotFound { path: PathBuf, message: String },
35
36    /// Failed to read repository references.
37    #[error("Failed to read references: {0}")]
38    ReferencesError(String),
39
40    /// Failed to read a commit object.
41    #[error("Failed to read commit {commit_id}: {message}")]
42    CommitReadError { commit_id: String, message: String },
43
44    /// Failed to read a tree object.
45    #[error("Failed to read tree: {0}")]
46    TreeReadError(String),
47
48    /// Failed to read a blob object.
49    #[error("Failed to read blob {blob_id}: {message}")]
50    BlobReadError { blob_id: String, message: String },
51
52    /// Generic git operation error.
53    #[error("Git operation failed: {0}")]
54    OperationFailed(String),
55}
56
57/// Errors related to Helix DB operations.
58#[derive(Error, Debug)]
59pub enum HelixError {
60    /// Failed to connect to Helix DB instance.
61    #[error("Failed to connect to Helix DB at {endpoint}: {message}")]
62    ConnectionFailed { endpoint: String, message: String },
63
64    /// Failed to create a node in Helix DB.
65    #[error("Failed to create {node_type} node: {message}")]
66    NodeCreationFailed { node_type: String, message: String },
67
68    /// Failed to create an edge in Helix DB.
69    #[error("Failed to create edge from {from_id} to {to_id}: {message}")]
70    EdgeCreationFailed {
71        from_id: String,
72        to_id: String,
73        message: String,
74    },
75
76    /// Query execution failed.
77    #[error("Query failed: {0}")]
78    QueryFailed(String),
79
80    /// Not yet implemented placeholder.
81    #[error("Helix DB integration not yet implemented: {0}")]
82    NotImplemented(String),
83}
84
85/// Errors related to client configuration.
86#[derive(Error, Debug)]
87pub enum ConfigError {
88    /// Missing required configuration field.
89    #[error("Missing required configuration: {0}")]
90    MissingField(String),
91
92    /// Invalid configuration value.
93    #[error("Invalid configuration value for {field}: {message}")]
94    InvalidValue { field: String, message: String },
95
96    /// Invalid endpoint URL.
97    #[error("Invalid endpoint URL: {0}")]
98    InvalidEndpoint(String),
99}