crossbundle_tools/
error.rs1#[cfg(feature = "apple")]
4use apple_bundle::plist;
5use displaydoc::Display;
6use std::path::PathBuf;
7use std::process::Command;
8use thiserror::Error;
9
10pub type Result<T> = std::result::Result<T, Error>;
12
13#[cfg(feature = "android")]
15#[derive(Display, Debug, Error)]
16pub enum AndroidError {
17 AndroidNdkNotFound,
19 FailedToReadSourceProperties,
21 InvalidSourceProperties(String),
23 GradleDependencyProjectNotFound(PathBuf),
25 GradleDependencyProjectNoBuildFile(PathBuf),
27 GradleNotFound,
29 BuildToolsNotFound,
31 NoPlatformsFound,
33 PlatformNotFound(u32),
35 UnsupportedTarget,
37 UnsupportedHost(String),
39 InvalidSemver,
41 InvalidBuildTarget(String),
43 InvalidAppWrapper(String),
45 InvalidBuildStrategy(String),
47 FailedToFindAndroidManifest(String),
49 UnableToFindNDKFile,
51 AndroidTools(#[from] android_tools::error::Error),
53 AndroidManifest(#[from] android_manifest::error::Error),
55}
56
57#[cfg(feature = "apple")]
59#[derive(Display, Debug, Error)]
60pub enum AppleError {
61 CodeSigningProfilesNotFound,
63 CodeSigningProfileNotProvided,
65 CodesignFailed(String),
67 ZipCommandFailed,
69 CodesignAllocateNotFound,
71 Simctl(simctl::Error),
73 TargetNotFound,
75 ResourcesNotFound,
77 InvalidBuildStrategy(String),
79 InvalidBuildTarget(String),
81 AssetsNotFound,
83 FailedToFindInfoPlist(String),
85 Plist(#[from] plist::Error),
87}
88
89#[derive(Display, Debug, Error)]
91#[ignore_extra_doc_attributes]
92pub enum Error {
93 CmdFailed(Command, String, String),
95 CmdNotFound(String),
97 CopyToFileFailed {
99 path: PathBuf,
100 cause: std::io::Error,
101 },
102 WidthAndHeightDifSizes,
104 IconsAlreadyExist,
106 FailedToFindManifest(PathBuf),
108 InvalidProfile(String),
110 ToolchainBinaryNotFound {
113 toolchain_path: PathBuf,
114 gnu_bin: String,
115 llvm_bin: String,
116 },
117 PathNotFound(PathBuf),
119 FailedToFindCargoManifest(String),
121 FailedToChooseShellStringColor(String),
124 Io(#[from] std::io::Error),
126 FsExtra(#[from] fs_extra::error::Error),
128 Zip(#[from] zip::result::ZipError),
130 #[cfg(feature = "android")]
132 Android(#[from] AndroidError),
133 ImageError(#[from] image::ImageError),
135 #[cfg(feature = "apple")]
137 Apple(#[from] AppleError),
138 AnyhowError(#[from] anyhow::Error),
140 OtherError(#[from] Box<dyn std::error::Error>),
142}
143
144pub trait CommandExt {
149 fn output_err(self, print_logs: bool) -> Result<std::process::Output>;
152}
153
154impl CommandExt for Command {
155 fn output_err(mut self, print_logs: bool) -> Result<std::process::Output> {
156 let output = match print_logs {
158 true => self.spawn().and_then(|p| p.wait_with_output())?,
159 false => self.output()?,
160 };
161 if !output.status.success() {
162 return Err(Error::CmdFailed(
163 self,
164 String::from_utf8_lossy(&output.stdout).to_string(),
165 String::from_utf8_lossy(&output.stderr).to_string(),
166 ));
167 }
168 Ok(output)
169 }
170}
171
172#[cfg(feature = "apple")]
173impl From<plist::Error> for Error {
174 fn from(error: plist::Error) -> Self {
175 AppleError::from(error).into()
176 }
177}
178
179#[cfg(feature = "apple")]
180impl From<simctl::Error> for Error {
181 fn from(error: simctl::Error) -> Self {
182 AppleError::Simctl(error).into()
183 }
184}
185
186#[cfg(feature = "android")]
187impl From<android_tools::error::Error> for Error {
188 fn from(error: android_tools::error::Error) -> Self {
189 AndroidError::AndroidTools(error).into()
190 }
191}