quilt_rs/workflow/
error.rs1use std::fmt;
4use std::ops::Deref;
5
6use thiserror::Error;
7
8pub(super) const SUPPORTED_META_SCHEMA: &str = "http://json-schema.org/draft-07/schema#";
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum SchemaKind {
15 Metadata,
16 Entries,
17}
18
19impl fmt::Display for SchemaKind {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 match self {
22 SchemaKind::Metadata => f.write_str("metadata_schema"),
23 SchemaKind::Entries => f.write_str("entries_schema"),
24 }
25 }
26}
27
28#[derive(Debug, Clone, PartialEq, Eq, Error)]
32pub enum RuleViolation {
33 #[error("a workflow is required by this bucket, but none was selected")]
34 WorkflowRequired,
35
36 #[error("a commit message is required by this workflow, but none was provided")]
37 MessageRequired,
38
39 #[error("package name {name:?} does not match the required handle_pattern {pattern:?}")]
40 HandleMismatch { name: String, pattern: String },
41
42 #[error("package metadata does not satisfy the workflow's metadata_schema: {0}")]
43 MetadataInvalid(String),
44
45 #[error("package entries do not satisfy the workflow's entries_schema: {0}")]
46 EntriesInvalid(String),
47}
48
49#[derive(Debug, Clone, PartialEq, Eq)]
55pub struct Violations(Vec<RuleViolation>);
56
57impl Violations {
58 #[must_use]
61 pub fn from_nonempty(list: Vec<RuleViolation>) -> Option<Self> {
62 (!list.is_empty()).then_some(Self(list))
63 }
64}
65
66impl Deref for Violations {
67 type Target = [RuleViolation];
68
69 fn deref(&self) -> &Self::Target {
70 &self.0
71 }
72}
73
74impl fmt::Display for Violations {
75 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
76 for violation in self.iter() {
77 write!(f, "\n - {violation}")?;
78 }
79 Ok(())
80 }
81}
82
83impl From<RuleViolation> for Violations {
84 fn from(violation: RuleViolation) -> Self {
85 Violations(vec![violation])
86 }
87}
88
89#[derive(Debug, Error)]
97pub enum WorkflowValidationError {
98 #[error("workflow {kind} is not a valid Draft-7 JSON Schema: {reason}")]
99 InvalidSchema { kind: SchemaKind, reason: String },
100
101 #[error("workflow {kind} uses `$ref`, which is not supported")]
102 UnsupportedRef { kind: SchemaKind },
103
104 #[error(
105 "workflow {kind} declares `$schema`: {value}, which is not supported \
106 (only the Draft-7 meta-schema {SUPPORTED_META_SCHEMA:?} is supported)"
107 )]
108 UnsupportedMetaSchema { kind: SchemaKind, value: String },
109
110 #[error("workflow handle_pattern {pattern:?} is not a valid regular expression: {reason}")]
111 InvalidHandlePattern { pattern: String, reason: String },
112
113 #[error("package does not satisfy the workflow:{0}")]
114 Rejected(Violations),
115}
116
117#[derive(Debug, Error)]
123pub enum ConfigError {
124 #[error("Workflow error: {0}")]
125 Workflow(String),
126
127 #[error("Invalid workflows config: {0}")]
130 InvalidWorkflowsConfig(String),
131
132 #[error(transparent)]
133 Uri(#[from] quilt_uri::UriError),
134}