Skip to main content

max / makenotwork

1.6 KB · 51 lines History Blame Raw
1 use thiserror::Error;
2
3 pub type Result<T> = std::result::Result<T, Error>;
4
5 #[derive(Debug, Error)]
6 pub enum Error {
7 #[error("tool not found: {0}")]
8 ToolNotFound(String),
9
10 #[error("resource not found: {0}")]
11 ResourceNotFound(String),
12
13 /// An in-flight request was cancelled — by the client (`notifications/
14 /// cancelled`) or by the app (a human took the buffer back). The `String`
15 /// is the cancelled request id.
16 #[error("request cancelled: {0}")]
17 Cancelled(String),
18
19 #[error("invalid arguments for tool `{tool}`: {message}")]
20 InvalidArgs { tool: String, message: String },
21
22 #[error("tool `{tool}` failed: {message}")]
23 ToolFailed { tool: String, message: String },
24
25 /// Registered refusal — the tool exists in the surface but is not offered.
26 /// The `reason` is stable text the model can act on.
27 #[error("tool `{tool}` is not offered: {reason}")]
28 Refused { tool: String, reason: String },
29
30 /// Write tool called without a grant for its capability. Includes a stable
31 /// suffix so small models learn not to retry.
32 #[error("tool `{tool}` requires capability `{capability}` which was not granted; do not retry")]
33 CapabilityDenied { tool: String, capability: String },
34
35 #[error("protocol error: {0}")]
36 Protocol(String),
37
38 #[error("transport error: {0}")]
39 Transport(String),
40
41 #[error(transparent)]
42 Json(#[from] serde_json::Error),
43
44 #[error(transparent)]
45 Io(#[from] std::io::Error),
46
47 #[cfg(feature = "ollama")]
48 #[error(transparent)]
49 Http(#[from] reqwest::Error),
50 }
51