rust_actions/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum Error {
5    #[error("Step not found: {0}")]
6    StepNotFound(String),
7
8    #[error("Args error: {0}")]
9    Args(String),
10
11    #[error("Expression error: {0}")]
12    Expression(String),
13
14    #[error("Assertion failed: {0}")]
15    Assertion(String),
16
17    #[error("IO error: {0}")]
18    Io(#[from] std::io::Error),
19
20    #[error("YAML parse error: {0}")]
21    Yaml(#[from] serde_yaml::Error),
22
23    #[error("JSON error: {0}")]
24    Json(#[from] serde_json::Error),
25
26    #[error("Step error: {0}")]
27    Step(#[from] StepError),
28
29    #[error("Container error: {0}")]
30    Container(String),
31
32    #[error("Environment variable not found: {0}")]
33    EnvVar(String),
34
35    #[error("Workflow not found: {path}")]
36    WorkflowNotFound { path: String },
37
38    #[error("Job not found: {job} in workflow {workflow}")]
39    JobNotFound { workflow: String, job: String },
40
41    #[error("Invalid file reference: {uses}")]
42    InvalidFileRef { uses: String },
43
44    #[error("Circular dependency detected: {chain}")]
45    CircularDependency { chain: String },
46
47    #[error("Job dependency not found: {job} requires {dependency}")]
48    JobDependencyNotFound { job: String, dependency: String },
49
50    #[error("{0}")]
51    Custom(String),
52}
53
54#[derive(Error, Debug)]
55pub enum StepError {
56    #[error("Assertion failed: {0}")]
57    Assertion(String),
58
59    #[error("{0}")]
60    Custom(String),
61}
62
63impl StepError {
64    pub fn assertion(msg: impl Into<String>) -> Self {
65        StepError::Assertion(msg.into())
66    }
67
68    pub fn custom(msg: impl Into<String>) -> Self {
69        StepError::Custom(msg.into())
70    }
71}
72
73pub type Result<T> = std::result::Result<T, Error>;