rustferry_android/
error.rs1use std::io;
2
3use camino::Utf8PathBuf;
4use thiserror::Error;
5
6#[derive(Debug, Error)]
8pub enum AndroidError {
9 #[error(transparent)]
11 Assets(#[from] rustferry_core::AssetError),
12 #[error(transparent)]
14 AssetPipeline(#[from] rustferry_codegen::AssetPipelineError),
15 #[error("invalid Android build request: {0}")]
17 InvalidRequest(String),
18 #[error("invalid external tool path: {reason}")]
20 InvalidExternalToolPath {
21 reason: &'static str,
23 },
24 #[error("invalid RustFerry configuration: {0}")]
26 InvalidConfig(String),
27 #[error("Android tool `{tool}` was not found; searched: {searched:?}. {fix}")]
29 ToolMissing {
30 tool: String,
32 searched: Vec<Utf8PathBuf>,
34 fix: String,
36 },
37 #[error(
39 "Android platform `{requested}` was not found; installed API levels: {installed:?}. {fix}"
40 )]
41 PlatformMissing {
42 requested: String,
44 installed: Vec<u32>,
46 fix: String,
48 },
49 #[error("complete Android SDK Build Tools were not found; searched: {searched:?}. {fix}")]
51 BuildToolsMissing {
52 searched: Vec<Utf8PathBuf>,
54 fix: String,
56 },
57 #[error("Android NDK linker for `{target}` was not found; searched: {searched:?}. {fix}")]
59 NdkLinkerMissing {
60 target: String,
62 searched: Vec<Utf8PathBuf>,
64 fix: String,
66 },
67 #[error("Cargo did not produce a cdylib for `{target}`; inspected artifacts: {searched:?}")]
69 NativeLibraryMissing {
70 target: String,
72 searched: Vec<Utf8PathBuf>,
74 },
75 #[error(
77 "Android DEX is required, but no .dex file was found in Cargo build-script OUT_DIRs: {searched:?}. Ensure the Android backend feature is enabled, then rebuild with Cargo JSON messages."
78 )]
79 MissingDex {
80 searched: Vec<Utf8PathBuf>,
82 },
83 #[error(
85 "Android component `{class_name}` is enabled, but its class was not found in merged DEX files: {searched:?}. Add the generated or prebuilt bridge input that implements this component."
86 )]
87 MissingDexClass {
88 class_name: String,
90 searched: Vec<Utf8PathBuf>,
92 },
93 #[error("could not interpret Cargo JSON output: {0}")]
95 CargoOutput(String),
96 #[error("could not start `{program}` during {stage}: {source}")]
98 CommandSpawn {
99 stage: String,
101 program: Utf8PathBuf,
103 #[source]
105 source: io::Error,
106 },
107 #[error("`{program}` timed out during {stage}; log: {log:?}")]
109 CommandTimedOut {
110 stage: String,
112 program: Utf8PathBuf,
114 log: Option<Utf8PathBuf>,
116 },
117 #[error(
119 "`{program}` produced more than {limit_bytes} bytes on {stream} during {stage}; its process tree was stopped; log: {log:?}"
120 )]
121 ProcessOutputTooLarge {
122 stage: String,
124 program: Utf8PathBuf,
126 stream: String,
128 limit_bytes: usize,
130 log: Option<Utf8PathBuf>,
132 },
133 #[error("`{program}` was interrupted during {stage}")]
135 CommandInterrupted {
136 stage: String,
138 program: Utf8PathBuf,
140 },
141 #[error("`{program}` failed during {stage} with status {status}; {summary}; log: {log:?}")]
143 CommandFailed {
144 stage: String,
146 program: Utf8PathBuf,
148 status: String,
150 summary: Box<String>,
152 log: Option<Utf8PathBuf>,
154 },
155 #[error("could not {operation} `{path}`: {source}")]
157 Io {
158 operation: &'static str,
160 path: Utf8PathBuf,
162 #[source]
164 source: io::Error,
165 },
166 #[error("APK ZIP operation failed for `{path}`: {message}")]
168 Zip {
169 path: Utf8PathBuf,
171 message: String,
173 },
174 #[error("APK validation failed for `{path}`: {reason}")]
176 InvalidArtifact {
177 path: Utf8PathBuf,
179 reason: String,
181 },
182 #[error("path is not valid UTF-8: {0:?}")]
184 NonUtf8Path(std::path::PathBuf),
185}
186
187pub(crate) fn io_error(
188 operation: &'static str,
189 path: impl Into<Utf8PathBuf>,
190 source: io::Error,
191) -> AndroidError {
192 AndroidError::Io {
193 operation,
194 path: path.into(),
195 source,
196 }
197}