1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use thiserror::Error;
/// Error that can happen when reading a PxTone project
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
pub enum ProjectReadError {
/// If a project contains this tag, it's an error.
#[error("anti operation")]
AntiOpreation,
/// Low level data read error (premature EOF, varint parsing error)
#[error("Error reading `{what}` at position {cursor} (source length: {len})")]
Data {
/// What kind of data failed to read
what: &'static str,
/// Last cursor position
cursor: usize,
/// Data source length
len: usize,
},
/// Format newer than supported
#[error("Format newer than supported")]
FmtNewer,
/// Unknown format
#[error("Unknown format")]
FmtUnknown,
/// Invalid/unsupported tag
#[error("Invalid/unsupported tag")]
InvalidTag,
/// Invalid/unsupported tag data
#[error("Invalid/unsupported tag data")]
InvalidData,
/// Error reading Ogg/vorbis data
#[error("Ogg/vorbis read error")]
OggvReadError,
/// ptcow was built with Ogg/vorbis support disabled
#[error("Ogg/vorbis support disabled")]
OggvSupportDisabled,
/// V4 (and earlier?) relies on the event list being a linked list, which would require
/// a lot of figuring out how to make it work with our implementation using `Vec`.
#[error("Unsupported old PxTone version")]
OldUnsupported,
/// We internally store overtone points as 16 bit integers, but they are encoded
/// as up-to 32 bit varints. Valid songs should never have overtone points this large,
/// but an invalid song could contain such a point.
#[error("Overtone point out of range: {0} (should be between in i32/i16 range for x/y)")]
OvertonePointOutOfRange(u32),
}
/// Error that can happen when saving a PxTone project
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
pub enum ProjectWriteError {
/// We don't support writing this format
#[error("Unsupported format for saving.")]
UnsupportedFmt,
/// We internally store the points as 16 bit due to various reasons, but the PxTone
/// format only supports 8 bit points for coord waves.
#[error("Coord wave point out of range (needs to be between 0 and 255")]
CoordWavePointOutOfRange,
}
/// Result of attempting to read a PxTone project
pub type ReadResult<T = ()> = Result<T, ProjectReadError>;
/// Result of attempting to write a PxTone project
pub type WriteResult<T = ()> = Result<T, ProjectWriteError>;