geolith_tiles_builder/sort/error.rs
1//! The error of the sort runs.
2
3use std::path::PathBuf;
4
5use crate::sort::block::BlockError;
6
7/// Why a sort run cannot be written or read.
8///
9/// A run that is cut, damaged or written by another version never yields a
10/// wrong entry: the reader stops with one of these.
11#[derive(Debug, thiserror::Error)]
12#[non_exhaustive]
13pub enum SortRunError {
14 /// A file operation on a run failed.
15 #[error("{op} {}", path.display())]
16 Io {
17 /// What was being done: `create`, `write`, `read`, `open`, `remove`.
18 op: &'static str,
19 /// The run file.
20 path: PathBuf,
21 /// What the operating system said.
22 #[source]
23 source: std::io::Error,
24 },
25
26 /// The file does not start like a sort run. Runs of an older version of
27 /// geolith have another layout: delete the folder and run phase 1 again.
28 #[error(
29 "{} is not a sort run of this version; delete the sort folder and build again",
30 path.display()
31 )]
32 NotARun {
33 /// The file.
34 path: PathBuf,
35 },
36
37 /// The run was written with a layout this version does not know.
38 #[error("{} has run layout {found}; this version reads layout {expected}", path.display())]
39 UnsupportedLayout {
40 /// The file.
41 path: PathBuf,
42 /// The layout number in the file.
43 found: u8,
44 /// The layout number this version reads.
45 expected: u8,
46 },
47
48 /// The file ends before the end marker: the write was cut, for example
49 /// by a full disk or a crash.
50 #[error("{} is cut: it ends at byte {at} without an end marker", path.display())]
51 Truncated {
52 /// The file.
53 path: PathBuf,
54 /// Where the file ended.
55 at: u64,
56 },
57
58 /// A block does not match its checksum: the disk or a copy damaged it.
59 #[error("{} is damaged: block {block} (at byte {at}) fails its checksum", path.display())]
60 BadChecksum {
61 /// The file.
62 path: PathBuf,
63 /// The block number, from 0.
64 block: u64,
65 /// Where the block starts.
66 at: u64,
67 },
68
69 /// A block passes its checksum but does not decode, or an entry cannot
70 /// be encoded.
71 #[error("{} has a bad block {block}: {source}", path.display())]
72 BadBlock {
73 /// The file.
74 path: PathBuf,
75 /// The block number, from 0.
76 block: u64,
77 /// What is wrong with the block.
78 #[source]
79 source: BlockError,
80 },
81
82 /// A block header or the end marker states a size that cannot be true.
83 #[error("{} has a bad header at byte {at}: {what}", path.display())]
84 BadHeader {
85 /// The file.
86 path: PathBuf,
87 /// Where the header starts.
88 at: u64,
89 /// What is wrong.
90 what: &'static str,
91 },
92
93 /// The end marker counts other blocks or entries than the file holds.
94 #[error(
95 "{} ends with {found} entries but its end marker says {expected}",
96 path.display()
97 )]
98 CountMismatch {
99 /// The file.
100 path: PathBuf,
101 /// The entries the end marker says.
102 expected: u64,
103 /// The entries the reader found.
104 found: u64,
105 },
106
107 /// Bytes follow the end marker.
108 #[error("{} has bytes after its end marker", path.display())]
109 TrailingBytes {
110 /// The file.
111 path: PathBuf,
112 },
113}