Skip to main content

cargo_apk2/
error.rs

1use {
2    cargo_subcommand::Error as SubcommandError,
3    ndk_build2::error::NdkError,
4    std::{io::Error as IoError, path::PathBuf, process::Command},
5    thiserror::Error,
6    toml::de::Error as TomlError,
7};
8
9#[derive(Debug, Error)]
10pub enum Error {
11    #[error(transparent)]
12    Subcommand(#[from] SubcommandError),
13    #[error("Command `{}` had a non-zero exit code.", format!("{:?}", .0).replace('"', ""))]
14    CmdFailed(Box<Command>),
15    #[error("Failed to parse config.")]
16    Config(#[from] TomlError),
17    #[error(transparent)]
18    Ndk(#[from] NdkError),
19    #[error(
20        "Java Development Kit is not found. \
21    Please set the path to the JDK with the $JAVA_HOME \
22    environment variable."
23    )]
24    JdkNotFound,
25    #[error(
26        "Groovy SDK is not found. \
27    Please set the path to the Groovy with the $GROOVY_HOME \
28    environment variable."
29    )]
30    GroovyNotFound,
31    #[error(
32        "Kotlin SDK is not found. \
33    Please set the path to the Kotlin with the $KOTLIN_HOME \
34    environment variable."
35    )]
36    KotlinNotFound,
37    #[error("Path `{0:?}` doesn't exist.")]
38    PathNotFound(PathBuf),
39    #[error(
40        "Scala SDK is not found. \
41    Please set the path to the Scala with the $SCALA_HOME \
42    environment variable."
43    )]
44    ScalaNotFound,
45    #[error(transparent)]
46    Io(#[from] IoError),
47    #[error("Configure a release keystore via `[package.metadata.android.signing.{0}]`")]
48    MissingReleaseKey(String),
49    #[error("`workspace=false` is unsupported")]
50    InheritedFalse,
51    #[error("`workspace=true` requires a workspace")]
52    InheritanceMissingWorkspace,
53    #[error("Failed to inherit field: `workspace.{0}` was not defined in workspace root manifest")]
54    WorkspaceMissingInheritedField(&'static str),
55    #[error("No artifact available. Please check lib, bins or examples of configuration.")]
56    NoArtifactAvailable,
57    #[error("Many artifacts are given ({0}), only support single artifact currently.")]
58    OnlySupportSingleArtifact(String),
59}
60
61impl Error {
62    pub fn invalid_args() -> Self {
63        Self::Subcommand(SubcommandError::InvalidArgs)
64    }
65}