Skip to main content

cargo_rapk/
error.rs

1use cargo_subcommand::Error as SubcommandError;
2use rndk::error::NdkError;
3use serde_json::Error as JsonError;
4use std::io::Error as IoError;
5use thiserror::Error;
6use toml::de::Error as TomlError;
7
8#[derive(Debug, Error)]
9pub enum Error {
10    #[error(transparent)]
11    Subcommand(#[from] SubcommandError),
12    #[error("Failed to parse config: {0}")]
13    Config(#[from] TomlError),
14    #[error("Manifest `{0}` must contain a `[package]` table")]
15    MissingPackageTable(std::path::PathBuf),
16    #[error(transparent)]
17    Ndk(#[from] NdkError),
18    #[error(transparent)]
19    Io(#[from] IoError),
20    #[error("`cargo metadata` failed: {0}")]
21    MetadataCommandFailed(String),
22    #[error("Failed to parse `cargo metadata` output")]
23    MetadataJson(#[from] JsonError),
24    #[error("Configure a release keystore via `[package.metadata.android.signing.{0}]`")]
25    MissingReleaseKey(String),
26    #[error("Set the keystore password via CARGO_RAPK_{0}_KEYSTORE_PASSWORD")]
27    MissingKeystorePassword(String),
28    #[error("`workspace=false` is unsupported")]
29    InheritedFalse,
30    #[error("`workspace=true` requires a workspace")]
31    InheritanceMissingWorkspace,
32    #[error("Workspace root manifest has no `[workspace]` table")]
33    MissingWorkspaceTable,
34    #[error("Failed to inherit field: `workspace.{0}` was not defined in workspace root manifest")]
35    WorkspaceMissingInheritedField(&'static str),
36    #[error("`version_name` must not be set manually; it is derived from the package version")]
37    VersionNameSet,
38    #[error("`version_code` must not be set manually; it is derived from the package version")]
39    VersionCodeSet,
40}
41
42impl Error {
43    pub fn invalid_args() -> Self {
44        Self::Subcommand(SubcommandError::InvalidArgs)
45    }
46}