agent_block_types/error.rs
1//! Typed error types for agent-block internals.
2//!
3//! All library/internal code uses `BlockError`.
4//! Only `main.rs` converts to `anyhow::Error` for CLI output.
5
6#[derive(Debug, thiserror::Error)]
7pub enum BlockError {
8 #[error("MCP error: {0}")]
9 Mcp(String),
10
11 #[error("mesh error: {0}")]
12 Mesh(String),
13
14 #[error("I/O error: {0}")]
15 Io(#[from] std::io::Error),
16
17 #[error("JSON error: {0}")]
18 Json(#[from] serde_json::Error),
19
20 #[error("script error: {0}")]
21 Script(String),
22
23 /// The script looked at what it needs and did not start — the raise a
24 /// block makes with `job.defer(reason)` (blocks/lib/job/init.lua), read
25 /// off the script failure by its prefix. The CLI exits 75 on it
26 /// (sysexits `EX_TEMPFAIL`) so the job manager records the run as
27 /// `deferred` rather than `failed`: nothing was done, and nothing was
28 /// wrong with the block. The payload is the reason.
29 #[error("deferred: {0}")]
30 Deferred(String),
31
32 #[error("timeout: {0}")]
33 Timeout(String),
34
35 #[error("runtime error: {0}")]
36 Runtime(String),
37
38 // Used by `crate::bus` (dispatcher + event) and `bridge::bus`.
39 #[error("bus error: {0}")]
40 Bus(String),
41
42 /// External `BlockConfig.shutdown_token` was cancelled while `run()`
43 /// was driving the script. The script may have been interrupted
44 /// mid-execution; in-flight handlers may have observed partial state.
45 #[error("cancelled")]
46 Cancelled,
47}
48
49pub type BlockResult<T> = Result<T, BlockError>;