diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-02-07 18:08:42 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-02-07 18:08:42 +0800 |
| commit | 4f184a439056d2b5dff7aa2fa1b1a73a1cbe9582 (patch) | |
| tree | 9d458e89ca8630dd402eec9dd519e333ed668fb3 /systems/asset/src/error.rs | |
| parent | f0001b45f91e7889c7060e45ac6c740401f7acb3 (diff) | |
Add asset system with file locking and atomic writes
Diffstat (limited to 'systems/asset/src/error.rs')
| -rw-r--r-- | systems/asset/src/error.rs | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/systems/asset/src/error.rs b/systems/asset/src/error.rs new file mode 100644 index 0000000..5dc529f --- /dev/null +++ b/systems/asset/src/error.rs @@ -0,0 +1,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), +} |
