use std::string::FromUtf8Error;
use camino::Utf8PathBuf;
use miette::Diagnostic;
use thiserror::Error;
use crate::Version;
pub type Result<T> = std::result::Result<T, AxoprojectError>;
#[derive(Debug, Error, Diagnostic)]
#[non_exhaustive]
pub enum AxoprojectError {
#[error(transparent)]
#[diagnostic(transparent)]
Axoasset(#[from] axoasset::AxoassetError),
#[error(transparent)]
#[diagnostic(transparent)]
Axoprocess(#[from] axoprocess::AxoprocessError),
#[cfg(feature = "cargo-projects")]
#[error(transparent)]
CargoMetadata(#[from] guppy::Error),
#[error(transparent)]
ParseChangelog(#[from] parse_changelog::Error),
#[error(transparent)]
#[diagnostic(transparent)]
Generic(#[from] GenericManifestParseError),
#[error(transparent)]
FromUtf8(#[from] FromUtf8Error),
#[cfg(feature = "cargo-projects")]
#[error("couldn't read Cargo.toml")]
ParseCargoToml {
#[source_code]
source: axoasset::SourceFile,
#[label]
span: Option<miette::SourceSpan>,
#[source]
details: axoasset::toml_edit::TomlError,
},
#[cfg(feature = "npm-projects")]
#[error("your package doesn't have a name:\n{manifest}")]
#[diagnostic(help("is it a workspace? We don't support that yet."))]
NamelessNpmPackage {
manifest: Utf8PathBuf,
},
#[cfg(feature = "npm-projects")]
#[error("Failed to read the binaries from your package.json:\n{manifest_path}")]
BuildInfoParse {
manifest_path: Utf8PathBuf,
#[source]
details: std::io::Error,
},
#[error("your workspace has inconsistent values for 'repository', refusing to select one:\n {file1}:\n {url1}\n {file2}:\n {url2}")]
#[diagnostic(severity("warning"))]
InconsistentRepositoryKey {
file1: Utf8PathBuf,
url1: String,
file2: Utf8PathBuf,
url2: String,
},
#[error("couldn't search for files in\n{dir}")]
AutoIncludeSearch {
dir: Utf8PathBuf,
#[source]
details: std::io::Error,
},
#[error("Your repository URL {url} couldn't be parsed.")]
#[diagnostic(help("only git-compatible URLs are supported."))]
UnknownRepoStyle {
url: String,
},
#[error("failed to parse your repo, current config has repo as: {repo}")]
#[diagnostic(help("We found a repo url but we had trouble parsing it. Please make sure it's entered correctly. This may be an error, and if so you should file an issue."))]
RepoParseError {
repo: String,
},
#[error(transparent)]
UrlParseError(#[from] url::ParseError),
#[error("Your repository URL {url} couldn't be parsed.")]
#[diagnostic(help("Only GitHub URLs are supported at the moment."))]
NotGitHubError {
url: String,
},
#[error("couldn't find a suitable changelog entry for {version} in {path}")]
ChangelogVersionNotFound {
path: Utf8PathBuf,
version: Version,
},
#[error("Your app has a Cargo.toml, but you don't appear to have cargo installed.")]
#[diagnostic(help("Is cargo in your PATH? You can install cargo via: https://rustup.rs"))]
CargoMissing {},
}
#[derive(Debug, Error, Diagnostic)]
pub enum ProjectError {
#[error("No workspace found; either your project doesn't have a Cargo.toml/dist.toml, or we couldn't read it")]
ProjectMissing {
#[related]
sources: Vec<AxoprojectError>,
},
#[error("We encountered an issue trying to read your workspace")]
ProjectBroken {
#[diagnostic_source]
cause: AxoprojectError,
},
}
#[derive(Debug, Error, Diagnostic)]
pub enum GenericManifestParseError {
#[error(
r#"dist workspace member {val} is missing prefix
members should be formatted like "dist:some/path
possible prefixes are: dist, cargo, npm"#
)]
NoPrefix {
val: String,
},
#[error(
"dist workspace member {val} has unknown {prefix} prefix
possible prefixes are: dist, cargo, npm"
)]
UnknownPrefix {
prefix: String,
val: String,
},
}