claude_pool/error.rs
1//! Error types for claude-pool.
2
3/// Errors that can occur in claude-pool operations.
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6 /// A slot with the given ID was not found.
7 #[error("slot not found: {0}")]
8 SlotNotFound(String),
9
10 /// A task with the given ID was not found.
11 #[error("task not found: {0}")]
12 TaskNotFound(String),
13
14 /// No slot became available within the timeout period.
15 #[error("no slot available after waiting {timeout_secs}s")]
16 NoSlotAvailable { timeout_secs: u64 },
17
18 /// The pool has been shut down and is no longer accepting work.
19 #[error("pool is shut down")]
20 PoolShutdown,
21
22 /// Pool-wide budget limit has been reached.
23 #[error("budget exhausted: spent {spent_microdollars} of {limit_microdollars} microdollars")]
24 BudgetExhausted {
25 /// Microdollars spent so far.
26 spent_microdollars: u64,
27 /// Microdollars budget limit.
28 limit_microdollars: u64,
29 },
30
31 /// A task's budget cap would exceed the remaining pool budget.
32 #[error("task budget ${task_budget_usd:.4} exceeds remaining pool budget ${remaining_usd:.4}")]
33 TaskBudgetExceedsRemaining {
34 /// The task's requested budget in USD.
35 task_budget_usd: f64,
36 /// Remaining pool budget in USD.
37 remaining_usd: f64,
38 },
39
40 /// An error from the underlying Claude CLI wrapper.
41 #[error("claude-wrapper error: {0}")]
42 Wrapper(#[from] claude_wrapper::Error),
43
44 /// JSON serialization/deserialization error.
45 #[error("json error: {0}")]
46 Json(#[from] serde_json::Error),
47
48 /// The Claude CLI appears to have stalled on a permission prompt.
49 ///
50 /// This occurs when the CLI requests tool approval and no human is present
51 /// to respond. The slot blocks on stdin until it times out or is killed.
52 #[error(
53 "permission prompt detected: {tool_name}. Add it to allowed_tools or use a broader permission mode"
54 )]
55 PermissionPromptDetected {
56 /// The tool or permission that was requested (best-effort extraction).
57 tool_name: String,
58 /// The raw stderr that triggered detection.
59 stderr: String,
60 /// The slot that was blocked.
61 slot_id: String,
62 },
63
64 /// Filesystem I/O error.
65 #[error("io error: {0}")]
66 Io(#[from] std::io::Error),
67
68 /// An error from the store backend.
69 #[error("store error: {0}")]
70 Store(String),
71}
72
73/// A convenience type alias for `Result<T, Error>`.
74pub type Result<T> = std::result::Result<T, Error>;