task_mcp/
error.rs

1//! Error types for task-mcp.
2
3use std::fmt;
4
5/// Errors that can occur during task management.
6#[derive(Debug)]
7pub enum Error {
8    /// Task with the given name was not found.
9    TaskNotFound { name: String },
10    /// Failed to spawn the process.
11    SpawnFailed { name: String, reason: String },
12    /// I/O error during file operations.
13    Io(std::io::Error),
14}
15
16impl fmt::Display for Error {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            Self::TaskNotFound { name } => write!(f, "task not found: {name}"),
20            Self::SpawnFailed { name, reason } => {
21                write!(f, "failed to spawn task '{name}': {reason}")
22            }
23            Self::Io(e) => write!(f, "I/O error: {e}"),
24        }
25    }
26}
27
28impl std::error::Error for Error {
29    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
30        match self {
31            Self::Io(e) => Some(e),
32            _ => None,
33        }
34    }
35}
36
37impl From<std::io::Error> for Error {
38    fn from(e: std::io::Error) -> Self {
39        Self::Io(e)
40    }
41}
42
43/// A specialized Result type for task-mcp operations.
44pub type Result<T> = std::result::Result<T, Error>;