Skip to main content

hh_record/
error.rs

1//! Recorder error types (CLAUDE.md: library errors via `thiserror`).
2
3use thiserror::Error;
4
5/// A specialization of [`hh_core::Error`] for recorder-originated failures,
6/// keeping the cause chain readable for the binary's `anyhow` context.
7///
8/// `portable-pty` returns `anyhow::Error`; we stringify it at the boundary
9/// (its `Display` form) rather than taking an `anyhow` dependency in this
10/// library, per CLAUDE.md ("Do not add a dependency without stating why").
11#[derive(Debug, Error)]
12pub enum RecordError {
13    /// Failed to spawn the child in the PTY (FR-1.1).
14    #[error("failed to spawn command `{command}` in pty: {reason}")]
15    Spawn {
16        /// The command line that failed.
17        command: String,
18        /// The stringified portable-pty error.
19        reason: String,
20    },
21    /// A PTY I/O or configuration error (resize, reader/writer, wait).
22    #[error("pty error: {0}")]
23    Pty(String),
24    /// A storage call failed while recording (session create, event append,
25    /// blob put, finalize). Wraps the `hh-core` error so the binary can attach
26    /// `anyhow::Context`.
27    #[error(transparent)]
28    Store(#[from] hh_core::Error),
29    /// The child could not be waited on, or its exit status was unreadable.
30    #[error("child process error: {0}")]
31    Child(String),
32    /// An unknown or unsupported adapter name was passed to `hh run --adapter`
33    /// (FR-1.5). Names the bad value and what's available so the user can fix it.
34    #[error("unknown adapter: {0}")]
35    Adapter(String),
36    /// A generic MCP proxy failure (server spawn, stdio I/O, store). The string
37    /// is a human-readable, actionable description (FR-2).
38    #[error("mcp proxy error: {0}")]
39    Mcp(String),
40    /// The `HH_SESSION_ID` referenced by an attached `hh mcp-proxy` does not
41    /// resolve to a recorded session (FR-2). Actionable: tells the user to run
42    /// standalone or re-run inside `hh run` rather than creating an orphan.
43    #[error("mcp attach failed: {0}")]
44    McpSession(String),
45}
46
47/// A `Result` alias for the recorder.
48pub type Result<T> = std::result::Result<T, RecordError>;