osu_file_parser/osu_file/hitobjects/
error.rs1use std::num::ParseIntError;
4
5use strum_macros::{EnumString, IntoStaticStr};
6use thiserror::Error;
7
8use crate::helper::macros::verbose_error_to_error;
9
10#[derive(Debug, Error)]
11#[error(transparent)]
12pub struct ParseError(#[from] ParseHitObjectError);
13
14#[derive(Debug, Error)]
15#[error("Expected combo skip count to be 3 bits")]
16pub struct ComboSkipCountTooHigh;
17
18#[derive(Debug, Error, IntoStaticStr, EnumString)]
19#[non_exhaustive]
20pub enum ParseColonSetError {
22    #[error("Failed to parse the first item")]
24    InvalidFirstItem,
25    #[error("The colon separator is missing")]
27    MissingSeparator,
28    #[error("Failed to parse the second item")]
29    InvalidSecondItem,
30}
31
32verbose_error_to_error!(ParseColonSetError);
33
34#[derive(Debug, Error, EnumString, IntoStaticStr)]
35#[non_exhaustive]
36pub enum ParseHitObjectError {
38    #[error("Invalid `hit_sound` value")]
40    InvalidHitSound,
41    #[error("Missing `hit_sound` field")]
43    MissingHitSound,
44    #[error("Missing `hit_sample` field")]
46    MissingHitSample,
47    #[error("Invalid `hit_sample` value")]
49    InvalidHitSample,
50    #[error("Invalid `x` value")]
52    InvalidX,
53    #[error("Missing `x` field")]
55    MissingX,
56    #[error("Invalid `y` value")]
58    InvalidY,
59    #[error("Missing `y` field")]
61    MissingY,
62    #[error("Missing `obj_type` field")]
64    MissingObjType,
65    #[error("Invalid `obj_type` value")]
67    InvalidObjType,
68    #[error("Missing `time` field")]
70    MissingTime,
71    #[error("Invalid `time` value")]
73    InvalidTime,
74    #[error("Invalid `curve_type` value")]
76    InvalidCurveType,
77    #[error("Missing `curve_type` field")]
79    MissingCurveType,
80    #[error("Invalid `curve_point` value")]
82    InvalidCurvePoint,
83    #[error("Missing `curve_point` field")]
85    MissingCurvePoint,
86    #[error("Invalid `edge_sound` value")]
88    InvalidEdgeSound,
89    #[error("Missing `edge_sound` field")]
91    MissingEdgeSound,
92    #[error("Invalid `edge_set` value")]
94    InvalidEdgeSet,
95    #[error("Missing `edge_set` field")]
97    MissingEdgeSet,
98    #[error("Invalid `slides_count` value")]
100    InvalidSlidesCount,
101    #[error("Missing `slides_count` field")]
103    MissingSlidesCount,
104    #[error("Invalid `length` value")]
106    InvalidLength,
107    #[error("Missing `length` field")]
109    MissingLength,
110    #[error("Invalid `end_time` value")]
112    InvalidEndTime,
113    #[error("Missing `end_time` field")]
115    MissingEndTime,
116    #[error("Unknown object type")]
118    UnknownObjType,
119}
120
121verbose_error_to_error!(ParseHitObjectError);
122
123#[derive(Debug, Error, EnumString, IntoStaticStr)]
124#[non_exhaustive]
125pub enum ParseHitSampleError {
127    #[error("Invalid `sample_set` value")]
128    InvalidSampleSet,
129    #[error("Invalid `index` value")]
130    InvalidIndex,
131    #[error("Invalid `volume` value")]
132    InvalidVolume,
133    #[error("Missing field separator")]
134    MissingSeparator,
135}
136
137verbose_error_to_error!(ParseHitSampleError);
138
139#[derive(Debug, Error)]
140#[non_exhaustive]
141pub enum ParseSampleSetError {
143    #[error("There was a problem parsing the `str` into an integer first")]
145    ParseValueError(#[from] ParseIntError),
146}
147
148#[derive(Debug, Error)]
149#[non_exhaustive]
150pub enum VolumeSetError {
152    #[error("The volume was too high, expected to be in range 1 ~ 100")]
153    VolumeTooHigh,
154    #[error("The volume was attempted to set to 0, expected to be in range 1 ~ 100")]
158    VolumeTooLow,
159}
160
161#[derive(Debug, Error)]
162#[non_exhaustive]
163pub enum ParseVolumeError {
165    #[error(transparent)]
166    VolumeSetError(#[from] VolumeSetError),
167    #[error(transparent)]
168    ParseIntError(#[from] ParseIntError),
169}
170
171#[derive(Debug, Error)]
172#[non_exhaustive]
173pub enum ParseCurveTypeError {
174    #[error("Unknown `CurveType` variant")]
175    UnknownVariant,
176}
177
178#[derive(Debug, Error)]
179#[non_exhaustive]
180pub enum ParseHitSoundError {
181    #[error(transparent)]
182    ParseIntError(#[from] ParseIntError),
183}