Skip to main content

hpr_flightdata/
error.rs

1//! Why a flight log couldn't be read.
2
3use thiserror::Error;
4
5/// An error reading a flight log: the text isn't the format it should be, or its data can't be a
6/// flight's record.
7#[derive(Debug, Clone, PartialEq, Error)]
8#[non_exhaustive]
9pub enum LogError {
10    /// A line of the file is malformed.
11    #[error("{format} line {line}: {message}")]
12    Syntax {
13        /// The file format, such as `.pf2`.
14        format: &'static str,
15        /// The 1-based line number.
16        line: usize,
17        /// What is wrong.
18        message: String,
19    },
20    /// The file isn't in the format asked for.
21    #[error("not read as {format}: {message}")]
22    NotThisFormat {
23        /// The format the file was read as.
24        format: &'static str,
25        /// Why it isn't one.
26        message: String,
27    },
28    /// The file is in none of the formats HPR Sim reads.
29    #[error("{message}")]
30    Unrecognized {
31        /// What the file looks like, and the formats HPR Sim reads.
32        message: String,
33    },
34    /// The file has no data rows.
35    #[error("{format}: the file has no data rows")]
36    NoData {
37        /// The file format.
38        format: &'static str,
39    },
40    /// A binary file's bytes aren't laid out as its format's, such as a frame whose checksum fails.
41    #[error("{format} byte {offset}: {message}")]
42    Binary {
43        /// The file format.
44        format: &'static str,
45        /// The 0-based offset of the byte where the reader found the fault.
46        offset: usize,
47        /// What is wrong.
48        message: String,
49    },
50    /// A zip archive can't be unpacked, or holds more than the bounds allow
51    /// ([`archive`](crate::archive)).
52    #[error("zip archive: {message}")]
53    Archive {
54        /// What is wrong.
55        message: String,
56    },
57    /// An `.xlsx` workbook's parts can't be read as one, or its sheets pass the bounds
58    /// ([`workbook`](crate::workbook)).
59    #[error("Excel workbook: {message}")]
60    Workbook {
61        /// What is wrong.
62        message: String,
63    },
64    /// A file that holds several records, a spreadsheet's sheets or a dump's recordings, read
65    /// with no choice of one where it holds no one record, or with a choice it doesn't take or
66    /// doesn't hold ([`import::read_one`](crate::import::read_one)).
67    #[error("{message}")]
68    Choice {
69        /// What is wrong, with the records the file holds.
70        message: String,
71    },
72    /// A header stated for a Raven FIP export that lost its own can't be read
73    /// ([`custom::fip_header_from_json`](crate::custom::fip_header_from_json)).
74    #[error("FIP header: {message}")]
75    FipHeader {
76        /// What is wrong.
77        message: String,
78    },
79    /// The file states its values in a unit the reader doesn't know, such as a PerfectFlite file
80    /// whose stated apogee carries no foot mark.
81    #[error("{format} line {line}: {message}")]
82    Unit {
83        /// The file format.
84        format: &'static str,
85        /// The 1-based line number.
86        line: usize,
87        /// What is wrong.
88        message: String,
89    },
90    /// A column mapping the caller gave can't read the file: it names no column or too many,
91    /// its clock isn't one of its columns or isn't in a unit of time, or a column's unit isn't
92    /// one the reader knows or doesn't measure what its quantity does
93    /// ([`generic::read_with`](crate::generic::read_with)); or a header line the caller stated
94    /// for a FIP export's rows isn't a FIP header, holds no altitude above the pad, or comes with
95    /// a pasted column numbered 0 ([`raven::read_rows`](crate::raven::read_rows),
96    /// [`raven::read_rows_around`](crate::raven::read_rows_around)).
97    #[error("column mapping: {message}")]
98    Mapping {
99        /// What is wrong.
100        message: String,
101    },
102    /// A file of binary records needs a layout the caller states, as a console capture does
103    /// ([`capture`](crate::capture)), or the layout the caller gave can't read it: no field or too
104    /// many, a name the table can't hold, names that state no clock, or a table past its bound
105    /// ([`records`](crate::records)).
106    #[error("record layout: {message}")]
107    Layout {
108        /// What is wrong.
109        message: String,
110    },
111}