Skip to main content

relay_knowledge/code/error/
mod.rs

1//! Defines blocking code-index boundary failures and I/O conversion.
2
3use std::{error::Error, fmt};
4
5/// Blocking code index failure.
6#[derive(Debug)]
7pub enum CodeIndexError {
8    Io(std::io::Error),
9    Git { args: Vec<String>, message: String },
10    TreeSitter(String),
11    InvalidInput(String),
12}
13
14impl fmt::Display for CodeIndexError {
15    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            Self::Io(error) => write!(formatter, "code index I/O failed: {error}"),
18            Self::Git { args, message } => {
19                write!(formatter, "git command failed ({args:?}): {message}")
20            }
21            Self::TreeSitter(message) => write!(formatter, "tree-sitter parse failed: {message}"),
22            Self::InvalidInput(message) => write!(formatter, "invalid code index input: {message}"),
23        }
24    }
25}
26
27impl Error for CodeIndexError {}
28
29impl From<std::io::Error> for CodeIndexError {
30    fn from(error: std::io::Error) -> Self {
31        Self::Io(error)
32    }
33}