use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[error("step job is missing header `{0}`")]
MissingHeader(&'static str),
#[error("step job has invalid `{header}` header `{value}`")]
InvalidStepHeader {
header: &'static str,
value: String,
},
#[error("submission header `{0}` uses the reserved `workflow.*` prefix")]
ReservedHeaderInSubmit(String),
#[error("run `{0}` is active with a different input; pick a fresh run_id")]
InputMismatch(String),
#[error(transparent)]
Queue(#[from] taquba::Error),
}
impl Error {
pub fn is_permanent(&self) -> bool {
match self {
Self::MissingHeader(_)
| Self::InvalidStepHeader { .. }
| Self::ReservedHeaderInSubmit(_)
| Self::InputMismatch(_) => true,
Self::Queue(e) => e.is_permanent(),
}
}
}
pub type Result<T> = std::result::Result<T, Error>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn workflow_variants_are_permanent() {
assert!(Error::MissingHeader("workflow.run_id").is_permanent());
assert!(
Error::InvalidStepHeader {
header: "workflow.step",
value: "not-a-u32".into(),
}
.is_permanent()
);
assert!(Error::ReservedHeaderInSubmit("workflow.foo".into()).is_permanent());
assert!(Error::InputMismatch("run-1".into()).is_permanent());
}
#[test]
fn queue_classifies_per_inner_variant() {
assert!(Error::Queue(taquba::Error::JobNotFound("job-1".into())).is_permanent());
assert!(Error::Queue(taquba::Error::InvalidState).is_permanent());
assert!(Error::Queue(taquba::Error::KvValueTooLarge { size: 10, max: 5 }).is_permanent());
}
}