rivets_mcp/
error.rs

1//! Error types for the rivets MCP server.
2
3use thiserror::Error;
4
5/// Errors that can occur in the rivets MCP server.
6#[derive(Debug, Error)]
7pub enum Error {
8    /// No workspace context has been set.
9    #[error("No workspace context set. Call set_context first.")]
10    NoContext,
11
12    /// Invalid argument value provided.
13    #[error("Invalid {field}: '{value}'. Valid values: {valid_values}")]
14    InvalidArgument {
15        /// The field name that had an invalid value.
16        field: &'static str,
17        /// The invalid value that was provided.
18        value: String,
19        /// Description of valid values.
20        valid_values: &'static str,
21    },
22
23    /// The requested issue was not found.
24    #[error("Issue not found: {0}")]
25    IssueNotFound(String),
26
27    /// The specified workspace was not found or path is invalid.
28    #[error("Workspace not found: {path}")]
29    WorkspaceNotFound {
30        /// The path that was not found.
31        path: String,
32        /// The underlying IO error, if any.
33        #[source]
34        source: Option<std::io::Error>,
35    },
36
37    /// Workspace exists but was not initialized via `set_context`.
38    #[error("Workspace not initialized: {0}. Call set_context first.")]
39    WorkspaceNotInitialized(String),
40
41    /// Failed to discover a rivets workspace.
42    #[error("No .rivets directory found in {0} or parent directories")]
43    NoRivetsDirectory(String),
44
45    /// Failed to load workspace configuration.
46    #[error("Failed to load config from '{path}': {reason}. Run 'rivets init' to create a valid configuration.")]
47    ConfigLoad {
48        /// The path to the config file.
49        path: String,
50        /// The reason for the failure.
51        reason: String,
52    },
53
54    /// An error from the rivets storage layer.
55    #[error("Storage error: {0}")]
56    Storage(#[from] rivets::error::Error),
57
58    /// An I/O error occurred.
59    #[error("I/O error: {0}")]
60    Io(#[from] std::io::Error),
61
62    /// JSON serialization/deserialization error.
63    #[error("JSON error: {0}")]
64    Json(#[from] serde_json::Error),
65
66    /// MCP protocol error.
67    #[error("MCP error: {0}")]
68    Mcp(String),
69}
70
71/// Result type for rivets MCP operations.
72pub type Result<T> = std::result::Result<T, Error>;