icedwright_trace/error.rs
1use crate::blob::BlobHash;
2
3/// Everything that can go wrong configuring, writing or reading a trace.
4#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum TraceError {
7 /// An environment variable holds a value the configuration cannot use.
8 #[error("{var}={value:?} is not valid: {expected}")]
9 BadEnv {
10 /// The variable.
11 var: &'static str,
12 /// What it held.
13 value: String,
14 /// What it may hold.
15 expected: &'static str,
16 },
17 /// The trace was written in a format this reader does not know.
18 #[error(
19 "trace format {found} is newer than this reader ({supported}); it was written by icedwright {writer}"
20 )]
21 NewerFormat {
22 /// The format in the trace.
23 found: u32,
24 /// The newest format this reader reads.
25 supported: u32,
26 /// The icedwright version that wrote it.
27 writer: String,
28 },
29 /// A step refers to a blob the archive does not hold.
30 #[error("missing blob {0}")]
31 MissingBlob(BlobHash),
32 /// Reading or writing failed.
33 #[error(transparent)]
34 Io(#[from] std::io::Error),
35 /// The bytes are not a readable zip archive, or a member cannot be decompressed.
36 #[error("corrupt archive: {0}")]
37 Corrupt(String),
38 /// The archive lacks a member every trace has.
39 #[error("corrupt archive: no {0} member")]
40 MissingMember(&'static str),
41 /// A member holds something other than what the format says it holds.
42 #[error("corrupt archive: {member}{}: {reason}", line.map(|l| format!(" line {l}")).unwrap_or_default())]
43 BadMember {
44 /// The member's name inside the archive.
45 member: String,
46 /// The one-based line, for line-oriented members.
47 line: Option<usize>,
48 /// What is wrong with it.
49 reason: String,
50 },
51 /// A blob's content does not hash to its name.
52 #[error("corrupt archive: {member} hashes to {found}")]
53 BlobMismatch {
54 /// The member's name inside the archive.
55 member: String,
56 /// The hash of what it holds.
57 found: BlobHash,
58 },
59 /// Bytes given as a PNG are not one, or a frame could not be encoded.
60 #[error("not a PNG: {0}")]
61 Png(String),
62 /// A source file path that cannot be stored under `source/`.
63 #[error("source path {0:?} must be relative and stay inside the workspace")]
64 BadSourcePath(String),
65 /// An attachment name that is not a plain file name.
66 #[error("attachment name {0:?} must be a plain file name, with no directories")]
67 BadAttachmentName(String),
68}