From 4f184a439056d2b5dff7aa2fa1b1a73a1cbe9582 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 7 Feb 2026 18:08:42 +0800 Subject: Add asset system with file locking and atomic writes --- systems/asset/src/error.rs | 106 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 systems/asset/src/error.rs (limited to 'systems/asset/src/error.rs') 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), +} -- cgit