1#[derive(thiserror::Error, Debug)]
5pub enum PackageError {
6 #[error("failed to read .aion ZIP archive: {0}")]
8 ArchiveRead(#[from] zip::result::ZipError),
9
10 #[error("missing required manifest.json entry")]
12 MissingManifest,
13
14 #[error(
16 "module `{module}` uses an engine-reserved namespace and must not ship as package bytecode"
17 )]
18 ReservedModuleName {
19 module: String,
21 },
22
23 #[error("failed to write .aion ZIP archive: {0}")]
25 ArchiveWrite(zip::result::ZipError),
26
27 #[error("failed to write .aion archive bytes: {source}")]
29 ArchiveWriteIo {
30 source: std::io::Error,
32 },
33
34 #[error("failed to parse manifest.json: {source}")]
36 ManifestParse {
37 source: serde_json::Error,
39 },
40
41 #[error("failed to serialise manifest.json: {source}")]
43 ManifestSerialise {
44 source: serde_json::Error,
46 },
47
48 #[error("unknown .aion format_version {found}")]
50 UnknownFormatVersion {
51 found: u32,
53 },
54
55 #[error("missing entry module `{module}` in beam set")]
57 MissingEntryModule {
58 module: String,
60 },
61
62 #[error("package integrity mismatch: expected version `{expected}`, computed `{computed}`")]
64 IntegrityMismatch {
65 expected: String,
67 computed: String,
69 },
70
71 #[error("malformed beam entry `{entry}`")]
73 MalformedBeamEntry {
74 entry: String,
76 },
77
78 #[error(
80 "archive contents inflate past the extraction limit of {limit} bytes; refusing to extract further"
81 )]
82 InflatedSizeExceeded {
83 limit: u64,
85 },
86}
87
88#[cfg(test)]
89mod tests {
90 use super::PackageError;
91
92 fn assert_send_sync<T: Send + Sync>() {}
93
94 #[test]
95 fn package_error_is_send_and_sync() {
96 assert_send_sync::<PackageError>();
97 }
98
99 #[test]
100 fn display_messages_name_the_failed_condition() {
101 assert_eq!(
102 PackageError::MissingManifest.to_string(),
103 "missing required manifest.json entry"
104 );
105 assert_eq!(
106 PackageError::ArchiveWriteIo {
107 source: std::io::Error::other("disk full"),
108 }
109 .to_string(),
110 "failed to write .aion archive bytes: disk full"
111 );
112 assert_eq!(
113 PackageError::UnknownFormatVersion { found: 99 }.to_string(),
114 "unknown .aion format_version 99"
115 );
116 assert_eq!(
117 PackageError::MissingEntryModule {
118 module: "workflow/main".to_owned(),
119 }
120 .to_string(),
121 "missing entry module `workflow/main` in beam set"
122 );
123 assert_eq!(
124 PackageError::IntegrityMismatch {
125 expected: "expected".to_owned(),
126 computed: "computed".to_owned(),
127 }
128 .to_string(),
129 "package integrity mismatch: expected version `expected`, computed `computed`"
130 );
131 assert_eq!(
132 PackageError::MalformedBeamEntry {
133 entry: "beam/workflow.beam".to_owned(),
134 }
135 .to_string(),
136 "malformed beam entry `beam/workflow.beam`"
137 );
138 assert_eq!(
139 PackageError::InflatedSizeExceeded { limit: 1024 }.to_string(),
140 "archive contents inflate past the extraction limit of 1024 bytes; refusing to extract further"
141 );
142 }
143}