1use std::string::FromUtf8Error;
4
5use camino::Utf8PathBuf;
6use miette::Diagnostic;
7use thiserror::Error;
8
9use crate::Version;
10
11pub type Result<T> = std::result::Result<T, AxoprojectError>;
13
14#[derive(Debug, Error, Diagnostic)]
16#[non_exhaustive]
17pub enum AxoprojectError {
18 #[error(transparent)]
20 #[diagnostic(transparent)]
21 Axoasset(#[from] axoasset::AxoassetError),
22
23 #[error(transparent)]
25 #[diagnostic(transparent)]
26 Axoprocess(#[from] axoprocess::AxoprocessError),
27
28 #[cfg(feature = "cargo-projects")]
30 #[error(transparent)]
31 CargoMetadata(#[from] guppy::Error),
32
33 #[error(transparent)]
35 ParseChangelog(#[from] parse_changelog::Error),
36
37 #[error(transparent)]
39 #[diagnostic(transparent)]
40 Generic(#[from] GenericManifestParseError),
41
42 #[error(transparent)]
44 FromUtf8(#[from] FromUtf8Error),
45
46 #[cfg(feature = "cargo-projects")]
48 #[error("couldn't read Cargo.toml")]
49 ParseCargoToml {
50 #[source_code]
52 source: axoasset::SourceFile,
53 #[label]
55 span: Option<miette::SourceSpan>,
56 #[source]
58 details: axoasset::toml_edit::TomlError,
59 },
60
61 #[cfg(feature = "npm-projects")]
63 #[error("your package doesn't have a name:\n{manifest}")]
64 #[diagnostic(help("is it a workspace? We don't support that yet."))]
65 NamelessNpmPackage {
66 manifest: Utf8PathBuf,
68 },
69
70 #[cfg(feature = "npm-projects")]
72 #[error("Failed to read the binaries from your package.json:\n{manifest_path}")]
73 BuildInfoParse {
74 manifest_path: Utf8PathBuf,
76 #[source]
78 details: std::io::Error,
79 },
80
81 #[error("your workspace has inconsistent values for 'repository', refusing to select one:\n {file1}:\n {url1}\n {file2}:\n {url2}")]
83 #[diagnostic(severity("warning"))]
84 InconsistentRepositoryKey {
85 file1: Utf8PathBuf,
87 url1: String,
89 file2: Utf8PathBuf,
91 url2: String,
93 },
94
95 #[error("couldn't search for files in\n{dir}")]
97 AutoIncludeSearch {
98 dir: Utf8PathBuf,
100 #[source]
102 details: std::io::Error,
103 },
104
105 #[error("Your repository URL {url} couldn't be parsed.")]
107 #[diagnostic(help("only git-compatible URLs are supported."))]
108 UnknownRepoStyle {
109 url: String,
111 },
112
113 #[error("failed to parse your repo, current config has repo as: {repo}")]
115 #[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."))]
116 RepoParseError {
117 repo: String,
119 },
120
121 #[error(transparent)]
123 UrlParseError(#[from] url::ParseError),
124
125 #[error("Your repository URL {url} couldn't be parsed.")]
127 #[diagnostic(help("Only GitHub URLs are supported at the moment."))]
128 NotGitHubError {
129 url: String,
131 },
132
133 #[error("couldn't find a suitable changelog entry for {version} in {path}")]
135 ChangelogVersionNotFound {
136 path: Utf8PathBuf,
138 version: Version,
140 },
141
142 #[error("Your app has a Cargo.toml, but you don't appear to have cargo installed.")]
144 #[diagnostic(help("Is cargo in your PATH? You can install cargo via: https://rustup.rs"))]
145 CargoMissing {},
146}
147
148#[derive(Debug, Error, Diagnostic)]
150pub enum ProjectError {
151 #[error("No workspace found; either your project doesn't have a Cargo.toml/dist.toml, or we couldn't read it")]
153 ProjectMissing {
154 #[related]
156 sources: Vec<AxoprojectError>,
157 },
158
159 #[error("We encountered an issue trying to read your workspace")]
161 ProjectBroken {
162 #[diagnostic_source]
164 cause: AxoprojectError,
165 },
166}
167
168#[derive(Debug, Error, Diagnostic)]
170pub enum GenericManifestParseError {
171 #[error(
173 r#"dist workspace member {val} is missing prefix
174members should be formatted like "dist:some/path
175possible prefixes are: dist, cargo, npm"#
176 )]
177 NoPrefix {
178 val: String,
180 },
181 #[error(
183 "dist workspace member {val} has unknown {prefix} prefix
184possible prefixes are: dist, cargo, npm"
185 )]
186 UnknownPrefix {
187 prefix: String,
189 val: String,
191 },
192}