Skip to main content

adk_devtools/
error.rs

1//! Error type for developer-tool operations.
2
3/// Errors produced by the developer tools.
4#[derive(Debug, thiserror::Error)]
5pub enum DevToolError {
6    /// The requested path resolves outside the workspace root.
7    #[error("path '{0}' escapes the workspace root")]
8    PathEscape(String),
9
10    /// A mutating operation was attempted on a read-only workspace.
11    #[error("workspace is read-only; '{0}' is not permitted")]
12    ReadOnly(&'static str),
13
14    /// `bash` execution is disabled for this workspace.
15    #[error("bash execution is disabled for this workspace")]
16    BashDisabled,
17
18    /// `edit_file` was called on a file that has not been read in this session.
19    #[error("file '{0}' must be read with read_file before it can be edited")]
20    NotRead(String),
21
22    /// `old_string` was not found in the target file.
23    #[error("no occurrence of the target string was found in '{0}'")]
24    NoMatch(String),
25
26    /// `old_string` matched more than once and `replace_all` was not set.
27    #[error(
28        "the target string occurs {count} times in '{path}'; pass replace_all=true \
29         or provide a more specific string"
30    )]
31    Ambiguous {
32        /// The file path.
33        path: String,
34        /// Number of occurrences found.
35        count: usize,
36    },
37
38    /// A bash command exceeded its timeout.
39    #[error("command timed out after {0:?}")]
40    Timeout(std::time::Duration),
41
42    /// An underlying I/O error.
43    #[error(transparent)]
44    Io(#[from] std::io::Error),
45
46    /// Any other error (e.g. invalid arguments, bad regex).
47    #[error("{0}")]
48    Other(String),
49}
50
51impl From<DevToolError> for adk_core::AdkError {
52    fn from(e: DevToolError) -> Self {
53        adk_core::AdkError::tool(e.to_string())
54    }
55}