1use miette::Diagnostic;
4use std::path::PathBuf;
5use thiserror::Error;
6
7#[derive(Error, Debug, Diagnostic)]
9pub enum Error {
10 #[error("Configuration error: {message}")]
12 #[diagnostic(code(cuenv_hooks::config::invalid))]
13 Configuration {
14 message: String,
16 },
17
18 #[error("I/O error during {operation}: {source}")]
20 #[diagnostic(code(cuenv_hooks::io::error))]
21 Io {
22 #[source]
24 source: std::io::Error,
25 path: Option<Box<std::path::Path>>,
27 operation: String,
29 },
30
31 #[error("Operation timed out after {seconds} seconds")]
33 #[diagnostic(code(cuenv_hooks::timeout))]
34 Timeout {
35 seconds: u64,
37 },
38
39 #[error("Execution state not found for instance: {instance_id}")]
41 #[diagnostic(code(cuenv_hooks::state::not_found))]
42 StateNotFound {
43 instance_id: String,
45 },
46
47 #[error("Serialization error: {message}")]
49 #[diagnostic(code(cuenv_hooks::serialization))]
50 Serialization {
51 message: String,
53 },
54
55 #[error("Process execution failed: {message}")]
57 #[diagnostic(code(cuenv_hooks::process))]
58 Process {
59 message: String,
61 },
62}
63
64impl Error {
65 pub fn configuration(message: impl Into<String>) -> Self {
67 Self::Configuration {
68 message: message.into(),
69 }
70 }
71
72 pub fn io(source: std::io::Error, path: Option<PathBuf>, operation: impl Into<String>) -> Self {
74 Self::Io {
75 source,
76 path: path.map(|p| p.into_boxed_path()),
77 operation: operation.into(),
78 }
79 }
80
81 pub fn state_not_found(instance_id: impl Into<String>) -> Self {
83 Self::StateNotFound {
84 instance_id: instance_id.into(),
85 }
86 }
87
88 pub fn serialization(message: impl Into<String>) -> Self {
90 Self::Serialization {
91 message: message.into(),
92 }
93 }
94
95 pub fn process(message: impl Into<String>) -> Self {
97 Self::Process {
98 message: message.into(),
99 }
100 }
101}
102
103pub type Result<T> = std::result::Result<T, Error>;