1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Errors.
use std::fmt;
/// Why an asset, a package or a lookup was rejected. Messages name the
/// offending value and, where it helps, what would be accepted.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum MicroError {
/// A name outside `[a-z0-9_-]` segments joined by `/`.
InvalidName(String),
/// A cell size that is not allowed (zero, more than 4 columns, or more
/// than 2 rows).
InvalidSize(String),
/// Alt text is mandatory and must be printable.
InvalidAlt(String),
/// A fallback that does not fit the asset's cells, or holds whitespace or
/// control characters.
InvalidFallback(String),
/// A malformed or unsupported manifest or pack file.
Manifest(String),
/// A package that breaks a hard limit (sizes, dimensions, frames).
Limit(String),
/// A path that escapes the package: absolute, `..`, or a link out of it.
UnsafePath(String),
/// An image whose header could not be read or whose format is not allowed.
Image(String),
/// No asset of this name in any layer.
UnknownAsset(String),
/// An I/O or archive error, with the path it happened on.
Io(String),
}
impl fmt::Display for MicroError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MicroError::InvalidName(name) => write!(
f,
"invalid micro asset name {name:?}: use lowercase letters, digits, `_` and `-`, \
with `/` between namespaces"
),
MicroError::InvalidSize(message)
| MicroError::InvalidAlt(message)
| MicroError::InvalidFallback(message)
| MicroError::Manifest(message)
| MicroError::Limit(message)
| MicroError::UnsafePath(message)
| MicroError::Image(message)
| MicroError::Io(message) => f.write_str(message),
MicroError::UnknownAsset(name) => write!(f, "unknown micro asset {name:?}"),
}
}
}
impl std::error::Error for MicroError {}