Skip to main content

hpr_io/ork/
error.rs

1//! Why a `.ork` file could not be read at all.
2
3use thiserror::Error;
4
5/// A `.ork` file that could not be opened or whose design document could not be parsed.
6///
7/// A reader that *can* go on raises a [`Warning`](super::Warning) instead: only the faults listed
8/// here stop the read, and each one leaves nothing useful behind.
9#[derive(Debug, Clone, PartialEq, Eq, Error)]
10#[non_exhaustive]
11pub enum OrkError {
12    /// The bytes start with neither a zip signature, a gzip signature, nor XML.
13    #[error("not a .ork file: it begins with {head}, which is neither zip, gzip nor XML")]
14    UnknownContainer {
15        /// The first bytes, printed as hex, to say what was seen instead.
16        head: String,
17    },
18    /// The zip container could not be read.
19    #[error("the zip container could not be read: {reason}")]
20    Zip {
21        /// What the zip reader said.
22        reason: String,
23    },
24    /// The gzip stream could not be decompressed.
25    #[error("the gzip stream could not be decompressed: {reason}")]
26    Gzip {
27        /// What the decompressor said.
28        reason: String,
29    },
30    /// The zip container holds no entry that could be the design document.
31    #[error("the zip container holds no design document (no `rocket.ork`, `.ork` or `.xml` entry)")]
32    NoDesign,
33    /// The design document is not UTF-8. OpenRocket writes UTF-8 and declares it.
34    #[error("the design document is not UTF-8")]
35    NotUtf8,
36    /// The design document is not well-formed XML.
37    #[error("the design document is not XML: {reason}")]
38    Xml {
39        /// What the XML parser said.
40        reason: String,
41    },
42    /// The document's root element is not `<openrocket>`.
43    #[error("the design document's root element is `{root}`, not `openrocket`")]
44    NotOpenRocket {
45        /// The root element's name.
46        root: String,
47    },
48    /// The container decompresses to more than
49    /// [`MAX_UNPACKED_BYTES`](super::container::MAX_UNPACKED_BYTES).
50    #[error("the file decompresses to more than the {limit}-byte limit")]
51    TooBig {
52        /// The limit that was passed.
53        limit: u64,
54    },
55    /// The document nests deeper than [`MAX_DEPTH`](super::MAX_DEPTH).
56    #[error("elements nest {depth} deep, past the limit of {limit}")]
57    TooDeep {
58        /// The limit that was passed.
59        limit: usize,
60        /// How deep the document nests.
61        depth: usize,
62    },
63    /// The root element carries no `version` attribute, or one that is not `major.minor`.
64    #[error("the schema version `{text}` is not `major.minor`")]
65    Version {
66        /// The attribute as written, or the empty string when it is missing.
67        text: String,
68    },
69}