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 a {format} file: {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 has no data rows.
29    #[error("{format}: the file has no data rows")]
30    NoData {
31        /// The file format.
32        format: &'static str,
33    },
34    /// The file states its values in a unit the reader doesn't know, such as a PerfectFlite file
35    /// whose stated apogee carries no foot mark.
36    #[error("{format} line {line}: {message}")]
37    Unit {
38        /// The file format.
39        format: &'static str,
40        /// The 1-based line number.
41        line: usize,
42        /// What is wrong.
43        message: String,
44    },
45}