Skip to main content

game_toolkit_dosaudio/
error.rs

1use core::fmt;
2
3/// Errors reported during configuration, port I/O and format loading.
4#[derive(Clone, Debug, Eq, PartialEq)]
5#[non_exhaustive]
6pub enum Error {
7    /// Invalid configuration or unsupported device selection.
8    Config(&'static str),
9    /// A port access attempted to move machine time backwards.
10    BackwardsTime,
11    /// The bounded command queue is full; no hardware state was changed.
12    QueueFull,
13    /// DMA completion events must be polled before advancing further.
14    IrqQueueFull,
15    /// A bounded synthesis trace overflowed and cannot be exported as complete.
16    CaptureOverflow,
17    /// A music file is malformed or uses an unsupported encoding.
18    Format(&'static str),
19    /// A timestamp, sample count or file size cannot be represented.
20    TooLarge,
21}
22
23impl fmt::Display for Error {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25        match self {
26            Self::Config(reason) | Self::Format(reason) => f.write_str(reason),
27            Self::BackwardsTime => f.write_str("machine time cannot move backwards"),
28            Self::QueueFull => {
29                f.write_str("sound command queue is full; render audio before retrying")
30            }
31            Self::IrqQueueFull => {
32                f.write_str("DMA completion queue is full; poll completion events before retrying")
33            }
34            Self::CaptureOverflow => f.write_str(
35                "synthesis capture overflowed; drain it more often or increase capacity",
36            ),
37            Self::TooLarge => f.write_str("time or file size exceeds the supported range"),
38        }
39    }
40}
41
42impl std::error::Error for Error {}
43
44/// Result type used by this crate.
45pub type Result<T> = core::result::Result<T, Error>;