osu_file_parser/osu_file/general/
error.rs

1use std::num::ParseIntError;
2
3use thiserror::Error;
4
5use crate::helper::{macros::unreachable_err_impl, ParseZeroOneBoolError};
6
7#[derive(Debug, Error)]
8#[non_exhaustive]
9/// Error used when there was a problem parsing the `General` section.
10pub enum ParseError {
11    /// A Field in `General` failed to parse as a `Integer`.
12    #[error(transparent)]
13    ParseIntError(#[from] ParseIntError),
14    /// A field in `General` failed to parse as a `bool` from an `Integer`.
15    #[error(transparent)]
16    ParseZeroOneBoolError(#[from] ParseZeroOneBoolError),
17    /// A field in `General` failed to parse as a `CountdownSpeed`.
18    #[error(transparent)]
19    ParseCountdownSpeedError(#[from] ParseCountdownSpeedError),
20    /// A field in `General` failed to parse as a `GameMode`.
21    #[error(transparent)]
22    ParseGameModeError(#[from] ParseGameModeError),
23    #[error(transparent)]
24    ParseSampleSetError(#[from] ParseSampleSetError),
25    #[error(transparent)]
26    ParseOverlayPositionError(#[from] ParseOverlayPositionError),
27    /// When the line isn't in a `key: value` format.
28    #[error("Invalid colon set, expected format of `key: value`")]
29    InvalidColonSet,
30    /// Invalid key name was used.
31    #[error("The key doesn't exist in `General`")]
32    InvalidKey,
33    /// Duplicate field in `General` were found.
34    #[error("Duplicate field were found in `General`")]
35    DuplicateField,
36    /// Field doesn't exist in version.
37    #[error("Field doesn't exist in version")]
38    InvalidVersion,
39    /// Invalid comma list, expected format of `key: value, value, value, ...`
40    #[error("Invalid comma list, expected format of `key: value, value, value, ...`")]
41    InvalidCommaList,
42}
43
44unreachable_err_impl!(ParseError);
45
46/// Error used when there's an error parsing the string as enum.
47#[derive(Debug, Error)]
48#[non_exhaustive]
49pub enum ParseGameModeError {
50    /// Error when the `GameMode` is not a valid enum.
51    #[error("Unknown `GameMode` variant")]
52    UnknownVariant,
53    /// Error trying to parse the `str` into an `Integer`.
54    #[error(transparent)]
55    ParseError(#[from] ParseIntError),
56}
57
58/// Error used when there's an error parsing the string as enum
59#[derive(Debug, Error)]
60#[non_exhaustive]
61pub enum ParseCountdownSpeedError {
62    /// The integer value is an unknown `CountdownSpeed` type.
63    #[error("Unknown `CountdownSpeed` variant")]
64    UnknownVariant,
65    /// There was a problem converting from `str` to an `Integer`.
66    #[error("There was a problem parsing the `str` as an `Integer`")]
67    ParseError(#[from] ParseIntError),
68}
69
70#[derive(Debug, Error)]
71#[non_exhaustive]
72pub enum ParseOverlayPositionError {
73    #[error("Unknown `OverlayPosition` variant")]
74    UnknownVariant,
75}
76
77#[derive(Debug, Error)]
78#[non_exhaustive]
79pub enum ParseSampleSetError {
80    #[error("Unknown `SampleSet` variant")]
81    UnknownVariant,
82}