wick_oci_utils/
error.rs

1use std::path::PathBuf;
2
3use oci_distribution::Reference;
4use thiserror::Error;
5
6#[derive(Error, Debug)]
7/// Crate error.
8#[non_exhaustive]
9pub enum OciError {
10  /// No version found in annotations
11  #[error("No version found in annotations")]
12  NoVersion(),
13
14  /// No manifest found in package
15  #[error("No manifest found in package")]
16  NoManifest,
17
18  /// Returned when reading an invalid manifest.
19  #[error("Invalid manifest found at {}. Try deleting your cache directory.",.0.display())]
20  InvalidManifest(PathBuf),
21
22  #[error("Reference '{0}' did not contain a tag or digest")]
23  NoTagOrDigest(String),
24  /// Error thrown when attempting to fetch an image with :latest when forbidden.
25  #[error("Configuration disallows fetching artifacts with the :latest tag ({0})")]
26  LatestDisallowed(String),
27
28  /// General fetch failure.
29  #[error("Could not fetch '{0}': {1}")]
30  OciFetchFailure(String, String),
31
32  /// untar failure failure.
33  #[error("Could not untar '{0}': {1}")]
34  UntarFile(String, String),
35
36  /// Failure during OCI push.
37  #[error("Could not push '{0}': {1}")]
38  OciPushFailure(Reference, Box<dyn std::error::Error + Send + Sync>),
39
40  /// Failure during OCI push.
41  #[error("Could not push manifest list '{0}': {1}")]
42  OciPushManifestListFailure(Reference, Box<dyn std::error::Error + Send + Sync>),
43
44  /// Failed to retrieve a manifest.
45  #[error("Could not retrieve manifest for '{0}': {1}")]
46  OciPullManifestFailure(Reference, Box<dyn std::error::Error + Send + Sync>),
47
48  /// Error for invalid URLs.
49  #[error("Could not parse OCI URL {0}: {1}")]
50  OCIParseError(String, String),
51
52  /// IO error for the local cache.
53  #[error(transparent)]
54  IOError(#[from] std::io::Error),
55
56  /// Upstream errors from oci-distribution
57  #[error(transparent)]
58  OciDistribution(#[from] oci_distribution::errors::OciDistributionError),
59
60  /// JSON Parse Error
61  #[error(transparent)]
62  JsonParseFailed(#[from] serde_json::Error),
63
64  /// YAML Parse Error
65  #[error(transparent)]
66  YamlParseFailed(#[from] serde_yaml::Error),
67
68  /// Failed to parse image reference location
69  #[error("Failed to parse the image reference: {0}")]
70  InvalidReferenceFormat(String),
71
72  /// Failed to push package
73  #[error("Failed to pull the package: {0}")]
74  PullFailed(String),
75
76  /// Tried to pull a layer that didn't include a title.
77  #[error("Wick package layers must contain a title")]
78  NoTitle,
79
80  /// Error returned when creating directories
81  #[error("Failed to create directory '{0}': {1}")]
82  CreateDir(PathBuf, #[source] std::io::Error),
83
84  /// Error returned when writing files
85  #[error("Failed to write file '{0}': {1}")]
86  WriteFile(PathBuf, #[source] std::io::Error),
87
88  /// Tried to publish a component that didn't have a name
89  #[error("Published components must be named")]
90  NoName,
91
92  /// Tried to pull a layer that didn't include at least one forward slash in the title.
93  #[error("Invalid layer path '{0}', layer path must contain at least one forward slash.")]
94  InvalidLayerPath(PathBuf),
95
96  /// Passed cache location could not be found.
97  #[error("Invalid cache location '{0}'")]
98  InvalidCache(wick_xdg::Error),
99
100  /// Failed to read downloaded package
101  #[error("Failed to read downloaded package: {0}")]
102  PackageReadFailed(String),
103
104  /// Failed to push package
105  #[error("Failed to push the package: {0}")]
106  PushFailed(String),
107
108  /// Returned when a pull would overwrite existing files and 'overwrite' is not set.
109  #[error("Refusing to overwrite {}. Set 'overwrite' to true to force.", .0.iter().map(|v|v.display().to_string()).collect::<Vec<_>>().join(", "))]
110  WouldOverwrite(Vec<PathBuf>),
111}