git_semantic/search/
error.rs1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum SearchError {
5 #[error("invalid date format '{value}' — expected YYYY-MM-DD")]
6 InvalidDateFormat {
7 value: String,
8 #[source]
9 source: chrono::ParseError,
10 },
11
12 #[error("no index found for this repository")]
13 IndexNotLoaded,
14
15 #[error(transparent)]
16 Embedding(#[from] crate::embedding::EmbeddingError),
17}
18
19impl SearchError {
20 pub fn hint(&self) -> Option<&'static str> {
22 match self {
23 Self::InvalidDateFormat { .. } => {
24 Some("Use the format YYYY-MM-DD, e.g. --after 2024-01-15")
25 }
26 Self::IndexNotLoaded => Some("Run: git-semantic index"),
27 Self::Embedding(_) => None, }
29 }
30
31 pub fn code(&self) -> &'static str {
33 match self {
34 Self::InvalidDateFormat { .. } => "E4001",
35 Self::IndexNotLoaded => "E4002",
36 Self::Embedding(_) => "E4003",
37 }
38 }
39}