Skip to main content

artifactize_core/verify_tools/
error.rs

1//! Keep transport failure causes distinct until the MCP response is rendered.
2use super::page::CursorError;
3use crate::config::ConfigError;
4use std::fmt;
5
6#[derive(Debug)]
7pub enum ArgumentsError {
8    ProjectRelative,
9    ProjectType,
10    UnknownTool(String),
11    Decode(serde_json::Error),
12    CursorType,
13    Cursor(CursorError),
14    ToolOptions(String),
15    LogOptions(String),
16}
17
18impl fmt::Display for ArgumentsError {
19    fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
20        match self {
21            Self::ProjectRelative => out.write_str("project must be an absolute folder."),
22            Self::ProjectType => out.write_str("Invalid arguments: project must be a string."),
23            Self::UnknownTool(name) => write!(out, "Unknown tool: {name}"),
24            Self::Decode(error) => write!(out, "Invalid arguments: {error}"),
25            Self::CursorType => out.write_str("cursor must be a string"),
26            Self::Cursor(error) => error.fmt(out),
27            Self::ToolOptions(message) | Self::LogOptions(message) => out.write_str(message),
28        }
29    }
30}
31
32#[derive(Debug)]
33pub enum Error {
34    Arguments(ArgumentsError),
35    Config(ConfigError),
36    Operation(String),
37    RequestOutsideProject,
38    Timeout,
39    Encode(serde_json::Error),
40    Cursor(CursorError),
41}
42
43impl fmt::Display for Error {
44    fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
45        match self {
46            Self::Arguments(error) => error.fmt(out),
47            Self::Config(error) => error.fmt(out),
48            Self::Operation(message) => out.write_str(message),
49            Self::RequestOutsideProject => out.write_str("Request not found in this repository."),
50            Self::Timeout => {
51                out.write_str("State unavailable within the MCP observation deadline.")
52            }
53            Self::Encode(error) => error.fmt(out),
54            Self::Cursor(error) => error.fmt(out),
55        }
56    }
57}
58
59// The shared operations expose their own user-facing diagnostic when they fail.
60impl From<String> for Error {
61    fn from(message: String) -> Self {
62        Self::Operation(message)
63    }
64}
65
66impl From<serde_json::Error> for Error {
67    fn from(error: serde_json::Error) -> Self {
68        Self::Encode(error)
69    }
70}