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
79#[cfg(test)]
80mod tests {
81 use super::PackageError;
82
83 fn assert_send_sync<T: Send + Sync>() {}
84
85 #[test]
86 fn package_error_is_send_and_sync() {
87 assert_send_sync::<PackageError>();
88 }
89
90 #[test]
91 fn display_messages_name_the_failed_condition() {
92 assert_eq!(
93 PackageError::MissingManifest.to_string(),
94 "missing required manifest.json entry"
95 );
96 assert_eq!(
97 PackageError::ArchiveWriteIo {
98 source: std::io::Error::other("disk full"),
99 }
100 .to_string(),
101 "failed to write .aion archive bytes: disk full"
102 );
103 assert_eq!(
104 PackageError::UnknownFormatVersion { found: 99 }.to_string(),
105 "unknown .aion format_version 99"
106 );
107 assert_eq!(
108 PackageError::MissingEntryModule {
109 module: "workflow/main".to_owned(),
110 }
111 .to_string(),
112 "missing entry module `workflow/main` in beam set"
113 );
114 assert_eq!(
115 PackageError::IntegrityMismatch {
116 expected: "expected".to_owned(),
117 computed: "computed".to_owned(),
118 }
119 .to_string(),
120 "package integrity mismatch: expected version `expected`, computed `computed`"
121 );
122 assert_eq!(
123 PackageError::MalformedBeamEntry {
124 entry: "beam/workflow.beam".to_owned(),
125 }
126 .to_string(),
127 "malformed beam entry `beam/workflow.beam`"
128 );
129 }
130}