summaryrefslogtreecommitdiff
path: root/systems/asset/src/error.rs
blob: 5dc529fd20c61a193e0114dfad721e91a77123e2 (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use std::path::PathBuf;

#[derive(Debug, thiserror::Error)]
pub enum DataReadError {
    #[error("IO error: {0}")]
    IoError(#[from] std::io::Error),

    #[error("Parse error: {0}")]
    ParseError(String),
}

#[derive(Debug, thiserror::Error)]
pub enum DataWriteError {
    #[error("IO error: {0}")]
    IoError(#[from] std::io::Error),
}

#[derive(Debug, thiserror::Error)]
pub enum DataApplyError {
    #[error("IO error: {0}")]
    IoError(#[from] std::io::Error),

    #[error("Asset file not found: {0}")]
    AssetFileNotFound(PathBuf),

    #[error("Pre-check failed: {0}")]
    PrecheckFailed(#[from] PrecheckFailed),
}

#[derive(Debug, thiserror::Error)]
pub enum PrecheckFailed {
    /// Lock file does not exist
    /// Means trying to apply a modification that cannot be applied
    #[error("Lock not found")]
    LockNotFound,

    /// Asset file does not exist
    /// Apply phase will fail due to this condition
    #[error("Asset not found")]
    AssetNotFound,

    // Note: !writed is allowed,
    // but writed without a TEMP_FILE is not allowed
    /// Handle produced a write
    /// but the temporary file does not exist, indicating an abnormal write operation
    #[error("Temp not found")]
    WritedButTempNotFound,

    /// Asset path is invalid
    /// This is not an issue that should arise from normal Handle creation flow
    #[error("Asset path invalid")]
    AssetPathInvalid,

    /// Temporary file cannot be moved
    #[error("Temp file not moveable")]
    TempNotMoveable,

    /// Asset file cannot be moved
    #[error("Asset file not writable")]
    AssetNotWritable,

    /// Handle is processing a cross-directory operation
    /// This is not atomic
    #[error("Handle is cross-directory")]
    HandleIsCrossDirectory,

    /// Asset file has no parent directory
    /// This is not a valid path for file operations
    #[error("Asset file has no parent directory")]
    HandleFileIsNoParent,

    /// A handle with the same path already exists
    /// This operation will cause a conflict
    #[error("Handle with same path exists")]
    HasSamePath,

    #[error("Lock on lock file")]
    LockOnLockFile,

    #[error("Temp file for temp file")]
    TempForTempFile,

    #[error("Asset path cannot be formatted")]
    FormatPathFailed,
}

#[derive(Debug, thiserror::Error)]
pub enum HandleLockError {
    #[error("Parse path failed")]
    ParsePathFailed,

    #[error("Asset file not found")]
    AssetFileNotFound(PathBuf),

    #[error("Read file name failed")]
    ReadFileNameFailed,

    #[error("Asset locked")]
    AssetLocked,

    #[error("IO error: {0}")]
    IoError(#[from] std::io::Error),

    #[error("Pre-check failed: {0}")]
    PrecheckFailed(#[from] PrecheckFailed),
}