1use crate::parse::MAX_PACKAGE_PATH_SEGMENT_BYTES;
6
7#[derive(PartialEq, Debug, thiserror::Error)]
8pub enum ParseError {
9 #[error("missing scheme")]
10 MissingScheme,
11
12 #[error("invalid scheme")]
13 InvalidScheme,
14
15 #[error("cannot have a scheme")]
16 CannotContainScheme,
17
18 #[error("invalid host")]
19 InvalidHost,
20
21 #[error("empty host")]
22 EmptyHost,
23
24 #[error("missing host")]
25 MissingHost,
26
27 #[error("host must be empty to imply absolute path")]
28 HostMustBeEmpty,
29
30 #[error("invalid path segment")]
31 InvalidPathSegment(#[source] PackagePathSegmentError),
32
33 #[error("invalid name")]
34 InvalidName(#[source] PackagePathSegmentError),
35
36 #[error("missing name")]
37 MissingName,
38
39 #[error("invalid variant")]
40 InvalidVariant(#[source] PackagePathSegmentError),
41
42 #[error("missing hash")]
43 MissingHash,
44
45 #[error("missing resource")]
46 MissingResource,
47
48 #[error("invalid hash")]
49 InvalidHash(#[source] fuchsia_hash::ParseHashError),
50
51 #[error("uppercase hex characters in hash")]
52 UpperCaseHash,
53
54 #[error("multiple hash query parameters")]
55 MultipleHashes,
56
57 #[error("cannot contain hash")]
58 CannotContainHash,
59
60 #[error("path must be root")]
61 PathMustBeRoot,
62
63 #[error("resource path failed to percent decode")]
64 ResourcePathPercentDecode(#[source] std::str::Utf8Error),
65
66 #[error("invalid resource path")]
67 InvalidResourcePath(#[source] crate::resource::ResourcePathError),
68
69 #[error("cannot contain a resource path (a URL fragment)")]
70 CannotContainResource,
71
72 #[error("extra path segments")]
73 ExtraPathSegments,
74
75 #[error("extra query parameters")]
76 ExtraQueryParameters,
77
78 #[error("cannot contain port")]
79 CannotContainPort,
80
81 #[error("cannot contain username")]
82 CannotContainUsername,
83
84 #[error("cannot contain password")]
85 CannotContainPassword,
86
87 #[error("cannot contain query parameters")]
88 CannotContainQueryParameters,
89
90 #[error("relative path URL cannot specify a package hash")]
91 RelativePathCannotSpecifyHash,
92
93 #[error("relative path URL cannot specify a variant")]
94 RelativePathCannotSpecifyVariant,
95
96 #[error("relative URL could not be parsed into a relative package path, Some({0:?}) != {1:?}")]
97 InvalidRelativePath(String, Option<String>),
98
99 #[error(
100 "relative URL with absolute path is not supported (relative path cannot start with `/`)"
101 )]
102 AbsolutePathNotSupported,
103
104 #[error("invalid repository URI")]
105 InvalidRepository,
106
107 #[error("url parse error")]
108 UrlParseError(#[from] url::ParseError),
109}
110
111#[derive(PartialEq, Eq, Debug, thiserror::Error)]
112pub enum PackagePathSegmentError {
113 #[error("empty segment")]
114 Empty,
115
116 #[error(
117 "segment too long. should be at most {MAX_PACKAGE_PATH_SEGMENT_BYTES} bytes, was {0} bytes"
118 )]
119 TooLong(usize),
120
121 #[error(
122 "package path segments must consist of only digits (0 to 9), lower-case letters (a to z), hyphen (-), underscore (_), and period (.). this contained {character:?}"
123 )]
124 InvalidCharacter { character: char },
125
126 #[error("package path segments cannot be a single period")]
127 DotSegment,
128
129 #[error("package path segments cannot be two periods")]
130 DotDotSegment,
131}