fast_fs/nav/nav_error.rs
1// <FILE>crates/fast-fs/src/nav/nav_error.rs</FILE> - <DESC>Navigation-specific error types</DESC>
2// <VERS>VERSION: 0.1.0</VERS>
3// <WCTX>Implementing nav module PRD</WCTX>
4// <CLOG>Initial creation</CLOG>
5
6//! Navigation error types
7//!
8//! These errors are specific to the navigation layer and provide more context
9//! than the base fast-fs errors.
10
11use std::path::PathBuf;
12use thiserror::Error;
13
14/// Errors specific to navigation operations
15#[derive(Error, Debug)]
16pub enum NavError {
17 /// Path does not exist
18 #[error("path not found: {0}")]
19 NotFound(PathBuf),
20
21 /// Path exists but is not a directory
22 #[error("not a directory: {0}")]
23 NotADirectory(PathBuf),
24
25 /// Access denied to path
26 #[error("permission denied: {0}")]
27 PermissionDenied(PathBuf),
28
29 /// Invalid filename for create/rename operations
30 #[error("invalid name: {0}")]
31 InvalidName(String),
32
33 /// Attempted to resolve/confirm when no operation is pending
34 #[error("no pending operation")]
35 NoPendingOperation,
36
37 /// Attempted to navigate history when none exists
38 #[error("no history")]
39 NoHistory,
40
41 /// I/O error with path context
42 #[error("I/O error at {path}: {source}")]
43 Io {
44 /// The path where the I/O error occurred
45 path: PathBuf,
46 /// The underlying I/O error
47 #[source]
48 source: std::io::Error,
49 },
50}
51
52impl NavError {
53 /// Create an I/O error with path context
54 pub fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
55 Self::Io {
56 path: path.into(),
57 source,
58 }
59 }
60
61 /// Convert a crate::Error to NavError with path context for I/O errors
62 ///
63 /// Use this instead of `.into()` when you have path context available,
64 /// to preserve the path in I/O error messages.
65 pub fn from_error_with_path(err: crate::Error, path: impl Into<PathBuf>) -> Self {
66 match err {
67 crate::Error::NotFound(p) => NavError::NotFound(p),
68 crate::Error::NotDirectory(p) => NavError::NotADirectory(p),
69 crate::Error::Io(io_err) => NavError::Io {
70 path: path.into(),
71 source: io_err,
72 },
73 }
74 }
75}
76
77impl From<crate::Error> for NavError {
78 fn from(err: crate::Error) -> Self {
79 match err {
80 crate::Error::NotFound(path) => NavError::NotFound(path),
81 crate::Error::NotDirectory(path) => NavError::NotADirectory(path),
82 // Note: Path context is lost here. Use from_error_with_path() when path is available.
83 crate::Error::Io(io_err) => NavError::Io {
84 path: PathBuf::new(),
85 source: io_err,
86 },
87 }
88 }
89}
90
91// <FILE>crates/fast-fs/src/nav/nav_error.rs</FILE>
92// <VERS>END OF VERSION: 0.1.0</VERS>