1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use crate::{folders::FolderGraphError, FileSerializationError, Resource, SerializedDataError};
use std::path::PathBuf;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum StartupError {
    #[error("couldn't deserialize yyp -- {0}")]
    BadYypDeserialize(String),

    #[error("yyp is wrong year version -- needed {0}, got {1}")]
    YypYearNotMatch(String, String),

    #[error("yyp is wrong version -- needed {0}, got {1}")]
    YypDoesNotMatch(semver::VersionReq, semver::Version),

    #[error("couldn't make or find the boss directory -- {0}")]
    BossDirectory(String),

    #[error("couldn't deserialize file at {filepath:?} -- {error}")]
    BadYyFile { filepath: PathBuf, error: String },

    #[error("couldn't read resource {} in yyp -- bad subpath given", .0.display())]
    BadResourceListing(PathBuf),

    #[error("couldn't load in {0} because {1}")]
    BadAssociatedData(String, YyResourceHandlerError),

    #[error("couldn't load in resource {name} in Asset Browser. Could be corrupted -- {error}")]
    BadResourceTree { name: String, error: String },

    #[error("bad path for yyp was given -- {yyp_filepath:?}, {error}")]
    BadYypPath {
        yyp_filepath: PathBuf,
        error: String,
    },

    #[error("a working directory path was given, but it was invalid")]
    BadWorkingDirectoryPath,

    #[error("bad arguments -- {0}")]
    BadCliArguments(String),
}

#[derive(Debug, Error)]
pub enum ResourceManipulationError {
    #[error(transparent)]
    FolderGraphError(#[from] FolderGraphError),

    #[error("cannot add that resource -- a {} of that name already exists", .0)]
    NameCollision(Resource),

    #[error("cannot use that name -- resource names must be [A-z_]\\w+")]
    BadName,

    #[error("cannot find that resource")]
    BadGet,

    #[error("internal error -- yyp-boss is in undefined state")]
    InternalError,

    #[error("resource cannot be manipulated yet -- yyp-boss does not have full support yet. please file an issue")]
    ResourceCannotBeManipulated,
}

#[derive(Debug, Error)]
pub enum YyResourceHandlerError {
    #[error(transparent)]
    FileSerializationError(#[from] FileSerializationError),

    #[error(transparent)]
    SerializedDataError(#[from] SerializedDataError),

    #[error("the given resource was not found or managed on the type")]
    ResourceNotFound,

    #[error("we cannot force serialization because the associated data could not be found")]
    CannotForceSerialization,
}