Skip to main content

hyperi_rustlib/deployment/
error.rs

1// Project:   hyperi-rustlib
2// File:      src/deployment/error.rs
3// Purpose:   Deployment validation error types
4// Language:  Rust
5//
6// License:   BUSL-1.1
7// Copyright: (c) 2026 HYPERI PTY LIMITED
8
9//! Deployment validation error types.
10
11use thiserror::Error;
12
13/// A single contract mismatch between app defaults and deployment artifact.
14#[derive(Debug, Clone)]
15pub struct ContractMismatch {
16    /// What was checked (e.g., "service.port", "EXPOSE port").
17    pub field: String,
18    /// Expected value (from app config).
19    pub expected: String,
20    /// Actual value (from deployment artifact).
21    pub actual: String,
22}
23
24impl std::fmt::Display for ContractMismatch {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        write!(
27            f,
28            "{}: expected '{}', got '{}'",
29            self.field, self.expected, self.actual
30        )
31    }
32}
33
34/// Errors from deployment validation and generation.
35#[derive(Debug, Error)]
36pub enum DeploymentError {
37    /// Failed to read a deployment artifact file.
38    #[error("failed to read {path}: {source}")]
39    ReadFile {
40        path: String,
41        #[source]
42        source: std::io::Error,
43    },
44
45    /// Failed to write a deployment artifact file.
46    #[error("failed to write {path}: {source}")]
47    WriteFile {
48        path: String,
49        #[source]
50        source: std::io::Error,
51    },
52
53    /// Failed to create a directory.
54    #[error("failed to create directory {path}: {source}")]
55    CreateDir {
56        path: String,
57        #[source]
58        source: std::io::Error,
59    },
60
61    /// Failed to parse YAML.
62    #[error("failed to parse YAML in {path}: {source}")]
63    ParseYaml {
64        path: String,
65        #[source]
66        source: serde_yaml_ng::Error,
67    },
68
69    /// File not found.
70    #[error("file not found: {0}")]
71    NotFound(String),
72}