1use std::path::PathBuf;
2
3use crate::model::TaskState;
4
5pub type Result<T, E = Error> = std::result::Result<T, E>;
6
7#[derive(Debug, thiserror::Error)]
8pub enum Error {
9 #[error("database error: {0}")]
10 Sqlite(#[from] rusqlite::Error),
11
12 #[error("task {0} not found")]
13 TaskNotFound(i64),
14
15 #[error("project {0} not found")]
16 ProjectNotFound(i64),
17
18 #[error(
19 "project {id} has {count} task(s) and cannot be deleted — set its weight to 0 to park \
20 it instead, which snoozes it without losing history"
21 )]
22 ProjectHasTasks { id: i64, count: i64 },
23
24 #[error("session {0} not found")]
25 SessionNotFound(i64),
26
27 #[error("cannot {action} a task in state '{from}'")]
28 InvalidTransition { from: TaskState, action: String },
29
30 #[error("task {id} is human-only: {reason}")]
31 HumanTask { id: i64, reason: String },
32
33 #[error("blocks dependency would create a cycle: {0}")]
34 DependencyCycle(String),
35
36 #[error(
37 "no default agent: none of the built-in agents ({probed}) were found on PATH; \
38 install one, or set `default_agent` in {} to a configured agent",
39 path.display()
40 )]
41 NoDefaultAgent { probed: String, path: PathBuf },
42
43 #[error("invalid agents config at {}: {message}", path.display())]
44 AgentConfigInvalid { path: PathBuf, message: String },
45
46 #[error("no agent named '{name}' ({origin}) in {}; defined agents: {known}", path.display())]
47 UnknownAgent {
48 name: String,
49 origin: &'static str,
50 path: PathBuf,
51 known: String,
52 },
53
54 #[error("{0}")]
55 Invalid(String),
56}