Skip to main content

rgc_chart/
errors.rs

1use std::fmt;
2use std::error::Error;
3// use crate::models::common::GameMode;
4
5#[derive(Debug)]
6pub enum ParseError<GameMode: fmt::Display + 'static> {
7    InvalidChart(String),
8    InvalidMode(String, GameMode),
9    EmptyChartData,
10    UnsupportedFormat,
11}
12
13#[derive(Debug)]
14pub enum WriteError<GameMode: fmt::Display + 'static> {
15    InvalidKeyCount(u8, String, String),
16    Unimpl(GameMode),
17}
18
19impl<GameMode: fmt::Display + 'static> fmt::Display for ParseError<GameMode> {
20    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21        match self {
22            Self::InvalidChart(error) => write!(f, "Failed to parse because Invalid chart data provided or file is malformed: {error}"),
23            Self::InvalidMode(mode, target) => write!(f, "Cannot parse because '{mode}' mode is invalid or not supported, parsing for {target}"),
24            Self::EmptyChartData => write!(f, "Cannot parse because empty chart data was provided"),
25            Self::UnsupportedFormat => write!(f, "Cannot parse because this is an unsupported file format"),
26        }
27    }
28}
29
30impl<GameMode: fmt::Display + 'static> fmt::Display for WriteError<GameMode> {
31    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32        match self {
33            Self::InvalidKeyCount(key_count, avaibable_key_counts, format) => write!(f, "Failed to write because {key_count}k is not supported, {format} only supports {avaibable_key_counts}"),
34            Self::Unimpl(_gamemode) => {unimplemented!()},
35        }
36    }
37}
38
39
40
41impl<GameMode: fmt::Debug + fmt::Display + 'static> Error for ParseError<GameMode> {}
42impl<GameMode: fmt::Debug + fmt::Display + 'static> Error for WriteError<GameMode> {}