Use thiserror crate
This commit is contained in:
parent
538ad72f2d
commit
9ffcf036f2
3 changed files with 16 additions and 20 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -227,6 +227,7 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"temp-file",
|
"temp-file",
|
||||||
"test-context",
|
"test-context",
|
||||||
|
"thiserror",
|
||||||
"typed-builder",
|
"typed-builder",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ temp-file = "0.1.7"
|
||||||
typed-builder = "0.12.0"
|
typed-builder = "0.12.0"
|
||||||
log = { version = "0.4.17", optional = true }
|
log = { version = "0.4.17", optional = true }
|
||||||
pretty_env_logger = { version = "0.4.0", optional = true }
|
pretty_env_logger = { version = "0.4.0", optional = true }
|
||||||
|
thiserror = "1.0.38"
|
||||||
|
|
||||||
[dependencies.clap]
|
[dependencies.clap]
|
||||||
version = "4.1.4"
|
version = "4.1.4"
|
||||||
|
|
|
@ -3,13 +3,14 @@ pub mod player_settings;
|
||||||
pub mod query;
|
pub mod query;
|
||||||
|
|
||||||
use crate::cmus::query::CmusQueryResponse;
|
use crate::cmus::query::CmusQueryResponse;
|
||||||
#[cfg(feature = "debug")]
|
|
||||||
use log::{debug, info};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt::{Debug, Display};
|
use std::fmt::Debug;
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use thiserror::Error;
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
|
use log::{debug, info};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Default)]
|
#[derive(Debug, PartialEq, Default)]
|
||||||
pub struct TrackMetadata {
|
pub struct TrackMetadata {
|
||||||
|
@ -33,35 +34,28 @@ pub struct Track {
|
||||||
pub position: u32,
|
pub position: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Error)]
|
||||||
pub enum CmusError {
|
pub enum CmusError {
|
||||||
|
#[error("Cmus running error: {0}")]
|
||||||
CmusRunningError(String),
|
CmusRunningError(String),
|
||||||
|
#[error("Unknown status")]
|
||||||
UnknownStatus,
|
UnknownStatus,
|
||||||
|
#[error("No status")]
|
||||||
NoStatus,
|
NoStatus,
|
||||||
|
#[error("Empty path")]
|
||||||
EmptyPath,
|
EmptyPath,
|
||||||
|
#[error("Duration error: {0}")]
|
||||||
DurationError(String),
|
DurationError(String),
|
||||||
|
#[error("Position error: {0}")]
|
||||||
PositionError(String),
|
PositionError(String),
|
||||||
|
#[error("Unknown error: {0}")]
|
||||||
UnknownError(String),
|
UnknownError(String),
|
||||||
|
#[error("Unknown AAA mode: {0}")]
|
||||||
UnknownAAAMode(String),
|
UnknownAAAMode(String),
|
||||||
|
#[error("Unknown shuffle mode: {0}")]
|
||||||
UnknownShuffleMode(String),
|
UnknownShuffleMode(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for CmusError {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
CmusError::CmusRunningError(s) => write!(f, "Cmus running error: {}", s),
|
|
||||||
CmusError::UnknownStatus => write!(f, "Unknown status"),
|
|
||||||
CmusError::NoStatus => write!(f, "No status"),
|
|
||||||
CmusError::EmptyPath => write!(f, "Empty path"),
|
|
||||||
CmusError::DurationError(s) => write!(f, "Duration error: {}", s),
|
|
||||||
CmusError::PositionError(s) => write!(f, "Position error: {}", s),
|
|
||||||
CmusError::UnknownError(s) => write!(f, "Unknown error: {}", s),
|
|
||||||
CmusError::UnknownAAAMode(s) => write!(f, "Unknown AAA mode: {}", s),
|
|
||||||
CmusError::UnknownShuffleMode(s) => write!(f, "Unknown shuffle mode: {}", s),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for TrackStatus {
|
impl FromStr for TrackStatus {
|
||||||
type Err = CmusError;
|
type Err = CmusError;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue