shuyi_sound/error.rs
1//! What can go wrong with decoded sound.
2
3use alloc::string::String;
4
5/// Why samples couldn't be made or read.
6#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
7#[non_exhaustive]
8pub enum Error {
9 /// A sound has one or two channels.
10 #[error("{0} channels; a sound has one or two")]
11 Channels(u32),
12 /// A rate of zero, or over the limit.
13 #[error("{rate} samples a second; it must be from 1 to {max}")]
14 Rate {
15 /// The rate asked for.
16 rate: u32,
17 /// The limit's largest.
18 max: u32,
19 },
20 /// Samples that don't divide into frames.
21 #[error("{samples} samples aren't whole frames of {channels} channels")]
22 PartialFrame {
23 /// How many samples there are.
24 samples: u64,
25 /// How many channels a frame has.
26 channels: u16,
27 },
28 /// More frames than the limit lets one source yield.
29 #[error("{frames} frames; the limit is {limit}")]
30 TooLong {
31 /// How many there are, or the most seen so far.
32 frames: u64,
33 /// The limit.
34 limit: u64,
35 },
36 /// A [`read`](crate::Source::read) into room for less than one frame.
37 #[error("room for {samples} samples can't hold a frame of {channels} channels")]
38 NoRoom {
39 /// How many samples the buffer holds.
40 samples: usize,
41 /// How many channels a frame has.
42 channels: u16,
43 },
44 /// A stream that has no frame ready yet and hasn't ended: it never waits for
45 /// one, so the reader comes back.
46 #[error("no frame is ready yet")]
47 Underrun,
48 /// A source that can't go back.
49 #[error("this source can't go back")]
50 NoRewind,
51 /// A valid file whose samples aren't one of the kinds read here.
52 #[error("{bits}-bit {kind} samples aren't read here")]
53 SampleKind {
54 /// `integer` or `float`.
55 kind: &'static str,
56 /// The width of one.
57 bits: u16,
58 },
59 /// A file that doesn't read.
60 #[error("not a readable {format} file: {reason}")]
61 Malformed {
62 /// `WAV` or `Ogg Vorbis`.
63 format: &'static str,
64 /// What the library said.
65 reason: String,
66 },
67}