sherpack_core/
error.rs

1//! Core error types
2
3use thiserror::Error;
4
5/// Information about a single validation error
6#[derive(Debug, Clone, PartialEq, Eq, Hash)]
7pub struct ValidationErrorInfo {
8    /// JSON path where the error occurred (e.g., "/image/tag")
9    pub path: String,
10    /// Human-readable error message
11    pub message: String,
12    /// Expected value/type (if applicable)
13    pub expected: Option<String>,
14    /// Actual value/type (if applicable)
15    pub actual: Option<String>,
16}
17
18#[derive(Error, Debug)]
19pub enum CoreError {
20    #[error("Pack not found: {path}")]
21    PackNotFound { path: String },
22
23    #[error("Invalid Pack.yaml: {message}")]
24    InvalidPack { message: String },
25
26    #[error("Failed to parse Pack.yaml: {0}")]
27    YamlParse(#[from] serde_yaml::Error),
28
29    #[error("Failed to parse JSON: {0}")]
30    JsonParse(#[from] serde_json::Error),
31
32    #[error("IO error: {0}")]
33    Io(#[from] std::io::Error),
34
35    #[error("Invalid version: {0}")]
36    InvalidVersion(#[from] semver::Error),
37
38    #[error("Values merge error: {message}")]
39    ValuesMerge { message: String },
40
41    #[error("Missing required field: {field}")]
42    MissingField { field: String },
43
44    #[error("Invalid schema: {message}")]
45    InvalidSchema { message: String },
46
47    #[error("Schema validation failed")]
48    SchemaValidation { errors: Vec<ValidationErrorInfo> },
49
50    #[error("Schema file not found: {path}")]
51    SchemaNotFound { path: String },
52
53    #[error("Invalid manifest: {message}")]
54    InvalidManifest { message: String },
55
56    #[error("Archive error: {message}")]
57    Archive { message: String },
58
59    #[error("File access error for '{path}': {message}")]
60    FileAccess { path: String, message: String },
61
62    #[error("Glob pattern error: {message}")]
63    GlobPattern { message: String },
64}
65
66impl CoreError {
67    /// Format validation errors for display
68    #[must_use]
69    pub fn format_validation_errors(errors: &[ValidationErrorInfo]) -> String {
70        errors
71            .iter()
72            .map(|e| format!("  - {}: {}", e.path, e.message))
73            .collect::<Vec<_>>()
74            .join("\n")
75    }
76}
77
78pub type Result<T> = std::result::Result<T, CoreError>;