dci_tool/error.rs
1//! Error types for the Direct Corpus Interaction (DCI) toolset.
2
3use std::path::PathBuf;
4
5/// Errors produced by corpus-interaction operations.
6///
7/// These are surfaced to the agent as tool-call errors, so their `Display`
8/// text is written to be intelligible to a language model deciding what to do
9/// next (e.g. "path escapes the corpus root" tells it to pick a path inside the
10/// corpus).
11#[derive(Debug, thiserror::Error)]
12#[non_exhaustive]
13pub enum DciError {
14 /// The corpus root could not be established (missing, not a directory, or
15 /// not canonicalizable).
16 #[error("invalid corpus root {path:?}: {reason}")]
17 InvalidRoot {
18 /// The offending path.
19 path: PathBuf,
20 /// Human-readable reason.
21 reason: String,
22 },
23
24 /// A requested path resolved outside the corpus root (path traversal or a
25 /// symlink escaping the jail).
26 #[error("path {requested:?} escapes the corpus root and was denied")]
27 PathEscape {
28 /// The path the caller asked for.
29 requested: String,
30 },
31
32 /// A requested path does not exist inside the corpus.
33 #[error("path {requested:?} was not found in the corpus")]
34 NotFound {
35 /// The path the caller asked for.
36 requested: String,
37 },
38
39 /// The caller supplied an invalid regular expression.
40 #[error("invalid search pattern: {0}")]
41 InvalidPattern(String),
42
43 /// The caller supplied an invalid glob.
44 #[error("invalid glob {glob:?}: {reason}")]
45 InvalidGlob {
46 /// The offending glob.
47 glob: String,
48 /// Why it failed to compile.
49 reason: String,
50 },
51
52 /// An operation exceeded its time budget.
53 #[error("operation timed out after {millis} ms")]
54 Timeout {
55 /// The configured budget in milliseconds.
56 millis: u64,
57 },
58
59 /// An underlying I/O failure.
60 #[error("i/o error on {path:?}: {source}")]
61 Io {
62 /// The path being operated on, if known.
63 path: PathBuf,
64 /// The underlying error.
65 #[source]
66 source: std::io::Error,
67 },
68
69 /// A background worker task failed to complete (runtime/cancellation).
70 #[error("corpus worker task failed: {0}")]
71 Worker(String),
72}
73
74/// Convenience alias for results in this crate.
75pub type Result<T> = std::result::Result<T, DciError>;