fits_header/error.rs
1//! Error type for fallible header operations.
2
3/// Errors from validated header mutations, ambiguous lookups, and oversized standalone
4/// serialization.
5///
6/// Parsing is lenient and does not produce these; header-only serialization
7/// ([`Header::to_header_bytes`](crate::Header::to_header_bytes)) is infallible.
8#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
9#[non_exhaustive]
10pub enum FitsError {
11 /// A bare-name `get`/`set`/`remove` addressed a keyword that occurs more than once.
12 /// Select one with an `(name, occurrence)` key.
13 #[error("keyword '{keyword}' occurs {count} times; select an occurrence")]
14 AmbiguousKeyword {
15 /// The duplicated keyword.
16 keyword: String,
17 /// How many times it occurs.
18 count: usize,
19 },
20
21 /// A keyword longer than the 8-character FITS field.
22 #[error("keyword '{keyword}' exceeds 8 characters")]
23 KeywordTooLong {
24 /// The offending keyword.
25 keyword: String,
26 },
27
28 /// A keyword containing bytes outside the FITS keyword set (`A-Z 0-9 - _`).
29 #[error("keyword '{keyword}' contains characters outside A-Z 0-9 - _")]
30 InvalidKeyword {
31 /// The offending keyword.
32 keyword: String,
33 },
34
35 /// An `(name, occurrence)` key targeted an occurrence that does not exist.
36 #[error("keyword '{keyword}' has no occurrence {occurrence} (found {count})")]
37 OccurrenceOutOfRange {
38 /// The keyword addressed.
39 keyword: String,
40 /// The 0-based occurrence requested.
41 occurrence: usize,
42 /// How many occurrences exist.
43 count: usize,
44 },
45
46 /// [`Header::to_bytes`](crate::Header::to_bytes) declined to zero-fill a declared data
47 /// segment larger than [`MAX_ZERO_FILL`](crate::MAX_ZERO_FILL). Serialize the header with
48 /// [`Header::to_header_bytes`](crate::Header::to_header_bytes) and supply the data yourself.
49 #[error("declared data size of {declared} bytes exceeds the to_bytes zero-fill cap ({max})")]
50 DataTooLarge {
51 /// The data size the header declares (saturated on overflow).
52 declared: u64,
53 /// The cap it exceeds ([`MAX_ZERO_FILL`](crate::MAX_ZERO_FILL)).
54 max: u64,
55 },
56}