use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum WasmCheckError {
#[error(
"no .wasm file found in `{}`\n tip: pass --file with the artifact path, e.g. target/wasm32-unknown-unknown/release/app.wasm\n tip: --file accepts globs, e.g. --file \"dist/*_bg-*.wasm\"\n tip: or list paths and globs under `files` in .wasmcheck.json",
.dir.display()
)]
NoWasmFound {
dir: PathBuf,
},
#[error("multiple .wasm files found: {found:?}; pass --file to select one")]
MultipleWasmFound {
found: Vec<String>,
},
#[error("file not found: {}", .0.display())]
FileNotFound(PathBuf),
#[error("config not found: {}", .0.display())]
ConfigNotFound(PathBuf),
#[error("baseline not found: {}", .0.display())]
BaselineNotFound(PathBuf),
#[error("i/o error: {0}")]
Io(#[from] std::io::Error),
#[error("failed to parse {}: {source}", .path.display())]
ConfigParse {
path: PathBuf,
source: serde_json::Error,
},
#[error(
"invalid size `{0}`; expected a non-negative number like \"280 KB\" (percentages such as \"5%\" are only allowed in `max_delta`)"
)]
InvalidSize(String),
#[error("invalid gzip level {0}; expected 0-9")]
InvalidGzipLevel(i64),
#[error("invalid brotli quality {0}; expected 0-11")]
InvalidBrotliQuality(i64),
#[error(
"invalid percentage `{0}`; expected a non-negative number with at most two decimals, like \"5%\""
)]
InvalidPercent(String),
#[error("unknown metric `{0}`; expected one of: raw, gzip, brotli")]
InvalidMetric(String),
#[error("{0}")]
BudgetExceeded(String),
#[error("failed to serialize config: {0}")]
Serialize(#[from] serde_json::Error),
#[error("wasm parse error: {0}")]
WasmParse(String),
}
impl WasmCheckError {
#[must_use]
pub fn is_budget_exceeded(&self) -> bool {
matches!(self, WasmCheckError::BudgetExceeded(_))
}
}