use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
pub enum CacheBusterError {
#[error("failed to read asset directory `{path}`")]
ReadDirectory {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("failed to read asset `{path}`")]
ReadFile {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("failed to rename asset `{from}` to `{to}`")]
Rename {
from: PathBuf,
to: PathBuf,
#[source]
source: std::io::Error,
},
#[error("failed to rewrite the source map reference in `{path}`")]
SourceMap {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error(
"`{path}` does not exist. The static-asset pipeline runs from the \
project root, where `static/` lives."
)]
MissingStaticDirectory { path: PathBuf },
#[error(
"no icon source. Provide `static/image/favicon/favicon.svg`, or a \
512x512 `static/image/favicon/favicon-512.png` if the art cannot be \
vectorised. The .ico, apple-touch icon and web-manifest icons are \
generated from whichever you provide."
)]
MissingFavicon,
#[error(
"both `favicon.svg` and `favicon-512.png` exist. Delete one: two \
sources drift the moment somebody updates only one of them."
)]
AmbiguousFavicon,
#[error(
"`{directory}` contains {count} file(s) that do not belong:{unexpected}\n\n\
Only these are allowed: {allowed}.\n\
Provide exactly one source — `favicon.svg`, or a 512x512 \
`favicon-512.png` — and let the rest be generated."
)]
UnexpectedFavicons {
directory: &'static str,
count: usize,
unexpected: String,
allowed: String,
},
#[error("`{path}` must be exactly {expected}x{expected}, but it is {width}x{height}")]
FaviconDimensions {
path: PathBuf,
expected: u32,
width: u32,
height: u32,
},
#[error("failed to read the dimensions of `{path}`: {reason}")]
ReadImage { path: PathBuf, reason: String },
#[error(
"{count} declared asset(s) are missing from the manifest, so every URL \
pointing at them would 404:{missing}\n\nRun the static-asset pipeline, \
or correct the paths."
)]
UnresolvedAssets { count: usize, missing: String },
#[error("`{path}` should be {expected}x{expected} but is {found}")]
IconMismatch {
path: String,
expected: u32,
found: String,
},
#[error(
"failed to parse `favicon.svg`. Note that it must not rely on system \
fonts — convert any text to paths."
)]
RenderIcon {
#[source]
source: resvg::usvg::Error,
},
#[error("cannot rasterise an icon at {size}x{size}")]
IconDimensions { size: u32 },
#[error("failed to encode a generated icon: {reason}")]
EncodeIcon { reason: String },
#[error("failed to write the generated icon `{path}`")]
WriteIcon {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("failed to parse the cache manifest at `{path}`")]
ParseManifest {
path: PathBuf,
#[source]
source: serde_json::Error,
},
#[error(
"`{path}` is missing but `static/` exists. Run `make gen_static_assets` \
— asset hashing happens at build time, not at startup."
)]
MissingManifest { path: PathBuf },
#[error("failed to write the cache manifest to `{path}`")]
WriteManifest {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("failed to serialize the cache manifest")]
SerializeManifest(#[source] serde_json::Error),
}