osu_file_parser/osu_file/timingpoints/
error.rs

1use std::num::ParseIntError;
2
3use strum_macros::{EnumString, IntoStaticStr};
4use thiserror::Error;
5
6use crate::helper::macros::verbose_error_to_error;
7
8#[derive(Debug, Error)]
9#[error(transparent)]
10pub struct ParseError(#[from] ParseTimingPointError);
11
12/// Error used when there was a problem parsing the [`TimingPoint`][super::TimingPoint].
13#[derive(Debug, Error, EnumString, IntoStaticStr)]
14#[non_exhaustive]
15pub enum ParseTimingPointError {
16    /// Invalid `time` value.
17    #[error("Invalid `time` value")]
18    InvalidTime,
19    /// Missing `beat_length` field.
20    #[error("Missing `beat_length` field")]
21    MissingBeatLength,
22    /// Missing `meter` field.
23    #[error("Missing `meter` field")]
24    MissingMeter,
25    /// Invalid `meter` value.
26    #[error("Invalid `meter` value")]
27    InvalidMeter,
28    /// Missing `sample_set` field.
29    #[error("Missing `sample_set` field")]
30    MissingSampleSet,
31    /// Invalid `sample_set` value.
32    #[error("Invalid `sample_set` value")]
33    InvalidSampleSet,
34    /// Missing `sample_index` field.
35    #[error("Missing `sample_index` field")]
36    MissingSampleIndex,
37    /// Invalid `sample_index` value.
38    #[error("Invalid `sample_index` value")]
39    InvalidSampleIndex,
40    /// Missing `volume` field.
41    #[error("Missing `volume` field")]
42    MissingVolume,
43    /// Invalid `volume` value.
44    #[error("Invalid `volume` value")]
45    InvalidVolume,
46    /// Missing `effects` field.
47    #[error("Missing `effects` field")]
48    MissingEffects,
49    /// Invalid `effects` value.
50    #[error("Invalid `effects` value")]
51    InvalidEffects,
52    /// Missing `uninherited` field.
53    #[error("Missing `uninherited` field")]
54    MissingUninherited,
55    /// Invalid `uninherited` value.
56    #[error("Invalid `uninherited` value")]
57    InvalidUninherited,
58}
59
60verbose_error_to_error!(ParseTimingPointError);
61
62/// There was some problem parsing the [`SampleSet`][super::SampleSet].
63#[derive(Debug, Error, PartialEq, Eq)]
64#[non_exhaustive]
65pub enum ParseSampleSetError {
66    /// The value failed to parse from a `str`.
67    #[error(transparent)]
68    ParseIntError(#[from] ParseIntError),
69}
70
71/// There was a problem parsing `str` as [`Effects`][super::Effects].
72#[derive(Debug, Error)]
73#[error(transparent)]
74pub struct ParseEffectsError(#[from] ParseIntError);
75
76#[derive(Debug, Error)]
77#[non_exhaustive]
78pub enum ParseSampleIndexError {
79    #[error(transparent)]
80    ParseIntError(#[from] ParseIntError),
81}
82
83/// Error for when there was a problem setting / parsing the volume.
84#[derive(Debug, Error, PartialEq, Eq)]
85#[non_exhaustive]
86pub enum VolumeError {
87    /// There was a problem parsing the `str` as [`Volume`][super::Volume].
88    #[error(transparent)]
89    ParseVolumeError(#[from] ParseIntError),
90}