torque_tracker_engine/file/
err.rs

1use std::error::Error;
2use std::fmt::{Display, Formatter};
3use std::io;
4
5#[derive(Debug)]
6pub enum LoadErr {
7    CantReadFile,
8    Invalid,
9    BufferTooShort,
10    /// A defect handler function returned ControlFlow::Break
11    Cancelled,
12    IO(io::Error),
13}
14
15impl From<io::Error> for LoadErr {
16    fn from(err: io::Error) -> Self {
17        if err.kind() == io::ErrorKind::UnexpectedEof {
18            Self::BufferTooShort
19        } else {
20            Self::IO(err)
21        }
22    }
23}
24
25impl Display for LoadErr {
26    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
27        write!(f, "{self:?}")
28    }
29}
30
31impl Error for LoadErr {}
32
33/// TODO: https://users.rust-lang.org/t/validation-monad/117894/6
34///
35/// this is a way cleaner and nicer approach. Provice a lot of data about the Error, like position in file, expected value, received value, ...
36/// maybe even allow to cancel the parsing via ControlFlow<(), ()>
37///
38/// load was partially successful. These are the defects that are in the now loaded project
39#[derive(Debug, Clone, Copy)]
40#[non_exhaustive]
41pub enum LoadDefect {
42    /// deletes the effect
43    UnknownEffect,
44    /// replaced with empty text
45    InvalidText,
46    /// tries to replace with a sane default value
47    OutOfBoundsValue,
48    /// skips loading of the pointed to value
49    OutOfBoundsPtr,
50}