1use std::num::ParseIntError;
2
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum ParseVersionError {
7 #[error(
8 "Wrong number of version parts, needs to have {0} parts but actual version had {1} parts"
9 )]
10 Size(usize, usize),
11
12 #[error("Invalid major version")]
13 Major(#[source] ParseIntError),
14
15 #[error("Invalid minor version")]
16 Minor(#[source] ParseIntError),
17
18 #[error("Invalid patch version")]
19 Patch(#[source] ParseIntError),
20
21 #[error(transparent)]
22 Semver(#[from] semver::Error),
23}
24
25#[derive(Error, Debug)]
26pub enum ParseVersionSpecError {
27 #[error(transparent)]
28 Op(#[from] ParseOpError),
29
30 #[error("Semver version req has no comparator, must have exactly one")]
31 SemverReqMissingComparator,
32
33 #[error("Semver version req has too many comparators, must have exactly one")]
34 SemverReqTooManyComparators,
35
36 #[error("Invalid or missing minor version")]
37 Minor,
38
39 #[error("Invalid or missing patch version")]
40 Patch,
41
42 #[error(transparent)]
43 Semver(#[from] semver::Error),
44}
45
46#[derive(Error, Debug)]
47#[error("Failed to parse the string as a valid version req")]
48pub struct ParseVersionReqError(#[from] ParseVersionSpecError);
49
50#[derive(Error, Debug)]
51pub enum ParseOpError {
52 #[error("{0:?} is not a supported operator, must be one of <, <=, =, >=, >")]
53 Op(semver::Op),
54}
55
56#[derive(Error, Debug)]
57pub enum ParseDependencyError {
58 #[error("The dependency string \"{0}\" does not match the RegEx")]
59 RegexMismatch(String),
60}