Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.

Commit 029d95d

Browse files
authored
Update errors.rs
1 parent 5ba5b2f commit 029d95d

1 file changed

Lines changed: 58 additions & 8 deletions

File tree

src/audio/errors.rs

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,81 @@
1-
use rodio::StreamError;
1+
use cpal::DevicesError;
2+
use rodio::cpal::{BackendSpecificError, DeviceNameError};
3+
use rodio::{PlayError, StreamError, decoder::DecoderError};
4+
use std::error::Error;
25
use std::io::ErrorKind;
36

4-
pub(super) enum AudioError {
5-
AudioError,
6-
FileError,
7+
#[derive(Debug)]
8+
pub enum AudioError {
9+
//also temp
10+
Default,
11+
IoError,
712
DecoderError,
813
FileNotLoaded,
14+
DeviceError(BackendSpecificError),
15+
NoDevice,
16+
//maybe unused
17+
#[allow(unused)]
18+
Other(Box<dyn Error + Send>),
919
}
1020

21+
//I still specify the full paths to show they're no std/core types
1122
impl From<rodio::StreamError> for AudioError {
1223
fn from(value: StreamError) -> Self {
1324
use rodio::StreamError as SE;
1425
match value {
1526
//temporary match-all
16-
SE::NoDevice => AudioError::AudioError,
27+
SE::NoDevice => AudioError::Default,
1728
//SE::
18-
_ => AudioError::AudioError,
29+
_ => AudioError::Default,
30+
}
31+
}
32+
}
33+
34+
impl From<rodio::DevicesError> for AudioError {
35+
fn from(value: rodio::DevicesError) -> Self {
36+
use rodio::DevicesError as SE;
37+
//will replace it later, is already a catch-all
38+
match value {
39+
SE::BackendSpecific { err } => AudioError::DeviceError(err),
40+
}
41+
}
42+
}
43+
44+
impl From<rodio::cpal::DeviceNameError> for AudioError {
45+
fn from(value: DeviceNameError) -> Self {
46+
use DeviceNameError as DNE;
47+
match value {
48+
DNE::BackendSpecific { err } => AudioError::DeviceError(err),
1949
}
2050
}
2151
}
2252

2353
impl From<std::io::Error> for AudioError {
2454
fn from(value: std::io::Error) -> Self {
25-
use std::io::Error as IOError;
2655
match value {
2756
//temp
28-
_ => AudioError::FileError,
57+
_ => AudioError::Default,
58+
}
59+
}
60+
}
61+
62+
impl From<rodio::PlayError> for AudioError {
63+
fn from(value: PlayError) -> Self {
64+
match value {
65+
PlayError::NoDevice => AudioError::NoDevice,
66+
//to be specified later
67+
PlayError::DecoderError(_) => AudioError::DecoderError,
68+
}
69+
}
70+
}
71+
72+
impl From<rodio::decoder::DecoderError> for AudioError {
73+
fn from(value: rodio::decoder::DecoderError) -> Self {
74+
match value {
75+
//also kinda temp match-all
76+
DecoderError::DecodeError(_) => AudioError::DecoderError,
77+
DecoderError::IoError(_) => AudioError::IoError,
78+
_ => AudioError::DecoderError,
2979
}
3080
}
3181
}

0 commit comments

Comments
 (0)