webserver_base/assets/
error.rs1use std::path::PathBuf;
4
5#[derive(Debug, thiserror::Error)]
11pub enum CacheBusterError {
12 #[error("failed to read asset directory `{path}`")]
14 ReadDirectory {
15 path: PathBuf,
16 #[source]
17 source: std::io::Error,
18 },
19
20 #[error("failed to read asset `{path}`")]
22 ReadFile {
23 path: PathBuf,
24 #[source]
25 source: std::io::Error,
26 },
27
28 #[error("failed to rename asset `{from}` to `{to}`")]
30 Rename {
31 from: PathBuf,
32 to: PathBuf,
33 #[source]
34 source: std::io::Error,
35 },
36
37 #[error(
39 "`{path}` does not exist. The static-asset pipeline runs from the \
40 project root, where `static/` lives."
41 )]
42 MissingStaticDirectory { path: PathBuf },
43
44 #[error(
46 "no icon source. Provide `static/image/favicon/favicon.svg`, or a \
47 512x512 `static/image/favicon/favicon-512.png` if the art cannot be \
48 vectorised. The .ico, apple-touch icon and web-manifest icons are \
49 generated from whichever you provide."
50 )]
51 MissingFavicon,
52
53 #[error(
55 "both `favicon.svg` and `favicon-512.png` exist. Delete one: two \
56 sources drift the moment somebody updates only one of them."
57 )]
58 AmbiguousFavicon,
59
60 #[error(
62 "`{directory}` contains {count} file(s) that do not belong:{unexpected}\n\n\
63 Only these are allowed: {allowed}.\n\
64 Provide exactly one source — `favicon.svg`, or a 512x512 \
65 `favicon-512.png` — and let the rest be generated."
66 )]
67 UnexpectedFavicons {
68 directory: &'static str,
69 count: usize,
70 unexpected: String,
71 allowed: String,
72 },
73
74 #[error("`{path}` must be exactly {expected}x{expected}, but it is {width}x{height}")]
76 FaviconDimensions {
77 path: PathBuf,
78 expected: u32,
79 width: u32,
80 height: u32,
81 },
82
83 #[error("failed to read the dimensions of `{path}`: {reason}")]
85 ReadImage { path: PathBuf, reason: String },
86
87 #[error(
89 "{count} declared asset(s) are missing from the manifest, so every URL \
90 pointing at them would 404:{missing}\n\nRun the static-asset pipeline, \
91 or correct the paths."
92 )]
93 UnresolvedAssets { count: usize, missing: String },
94
95 #[error("`{path}` should be {expected}x{expected} but is {found}")]
97 IconMismatch {
98 path: String,
99 expected: u32,
100 found: String,
101 },
102
103 #[error(
105 "failed to parse `favicon.svg`. Note that it must not rely on system \
106 fonts — convert any text to paths."
107 )]
108 RenderIcon {
109 #[source]
110 source: resvg::usvg::Error,
111 },
112
113 #[error("cannot rasterise an icon at {size}x{size}")]
115 IconDimensions { size: u32 },
116
117 #[error("failed to encode a generated icon: {reason}")]
120 EncodeIcon { reason: String },
121
122 #[error("failed to write the generated icon `{path}`")]
124 WriteIcon {
125 path: PathBuf,
126 #[source]
127 source: std::io::Error,
128 },
129
130 #[error("failed to parse the cache manifest at `{path}`")]
132 ParseManifest {
133 path: PathBuf,
134 #[source]
135 source: serde_json::Error,
136 },
137
138 #[error(
140 "`{path}` is missing but `static/` exists. Run `make gen_static_assets` \
141 — asset hashing happens at build time, not at startup."
142 )]
143 MissingManifest { path: PathBuf },
144
145 #[error("failed to write the cache manifest to `{path}`")]
147 WriteManifest {
148 path: PathBuf,
149 #[source]
150 source: std::io::Error,
151 },
152
153 #[error("failed to serialize the cache manifest")]
155 SerializeManifest(#[source] serde_json::Error),
156}