moonpool_sim/storage/
error.rs1use crate::sim::state::FileId;
4use std::io;
5use thiserror::Error;
6
7#[derive(Debug, Clone, PartialEq, Eq, Error)]
9pub enum StorageError {
10 #[error("file not found: {path}")]
12 NotFound {
13 path: String,
15 },
16
17 #[error("file already exists: {path}")]
19 AlreadyExists {
20 path: String,
22 },
23
24 #[error("invalid file handle: {file_id:?}")]
26 InvalidFileHandle {
27 file_id: FileId,
29 },
30
31 #[error("file is closed: {file_id:?}")]
33 FileClosed {
34 file_id: FileId,
36 },
37
38 #[error("I/O error on {file_id:?} ({kind:?}): {message}")]
40 Io {
41 file_id: FileId,
43 kind: io::ErrorKind,
45 message: String,
47 },
48}
49
50impl From<StorageError> for io::Error {
51 fn from(e: StorageError) -> Self {
52 let kind = match &e {
53 StorageError::NotFound { .. } => io::ErrorKind::NotFound,
54 StorageError::AlreadyExists { .. } => io::ErrorKind::AlreadyExists,
55 StorageError::InvalidFileHandle { .. } => io::ErrorKind::NotFound,
56 StorageError::FileClosed { .. } => io::ErrorKind::BrokenPipe,
57 StorageError::Io { kind, .. } => *kind,
58 };
59 io::Error::new(kind, e.to_string())
60 }
61}