cargo_nvim/
error.rs

1// src/error.rs
2use std::fmt;
3
4#[derive(Debug)]
5pub enum Error {
6    CommandFailed { command: String, details: String },
7    RuntimeError(String),
8    IoError(std::io::Error),
9}
10
11impl fmt::Display for Error {
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        match self {
14            Error::CommandFailed { command, details } => {
15                write!(f, "Cargo command '{}' failed: {}", command, details)
16            }
17            Error::RuntimeError(msg) => write!(f, "Runtime error: {}", msg),
18            Error::IoError(err) => write!(f, "IO error: {}", err),
19        }
20    }
21}
22
23impl std::error::Error for Error {}
24
25impl From<std::io::Error> for Error {
26    fn from(err: std::io::Error) -> Self {
27        Error::IoError(err)
28    }
29}
30
31impl From<Error> for mlua::Error {
32    fn from(err: Error) -> Self {
33        mlua::Error::RuntimeError(err.to_string())
34    }
35}