fast-fs 0.2.1

High-speed async file system traversal library with batteries-included file browser component
Documentation
// <FILE>crates/fast-fs/src/nav/nav_error.rs</FILE> - <DESC>Navigation-specific error types</DESC>
// <VERS>VERSION: 0.1.0</VERS>
// <WCTX>Implementing nav module PRD</WCTX>
// <CLOG>Initial creation</CLOG>

//! Navigation error types
//!
//! These errors are specific to the navigation layer and provide more context
//! than the base fast-fs errors.

use std::path::PathBuf;
use thiserror::Error;

/// Errors specific to navigation operations
#[derive(Error, Debug)]
pub enum NavError {
    /// Path does not exist
    #[error("path not found: {0}")]
    NotFound(PathBuf),

    /// Path exists but is not a directory
    #[error("not a directory: {0}")]
    NotADirectory(PathBuf),

    /// Access denied to path
    #[error("permission denied: {0}")]
    PermissionDenied(PathBuf),

    /// Invalid filename for create/rename operations
    #[error("invalid name: {0}")]
    InvalidName(String),

    /// Attempted to resolve/confirm when no operation is pending
    #[error("no pending operation")]
    NoPendingOperation,

    /// Attempted to navigate history when none exists
    #[error("no history")]
    NoHistory,

    /// I/O error with path context
    #[error("I/O error at {path}: {source}")]
    Io {
        /// The path where the I/O error occurred
        path: PathBuf,
        /// The underlying I/O error
        #[source]
        source: std::io::Error,
    },
}

impl NavError {
    /// Create an I/O error with path context
    pub fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
        Self::Io {
            path: path.into(),
            source,
        }
    }

    /// Convert a crate::Error to NavError with path context for I/O errors
    ///
    /// Use this instead of `.into()` when you have path context available,
    /// to preserve the path in I/O error messages.
    pub fn from_error_with_path(err: crate::Error, path: impl Into<PathBuf>) -> Self {
        match err {
            crate::Error::NotFound(p) => NavError::NotFound(p),
            crate::Error::NotDirectory(p) => NavError::NotADirectory(p),
            crate::Error::Io(io_err) => NavError::Io {
                path: path.into(),
                source: io_err,
            },
        }
    }
}

impl From<crate::Error> for NavError {
    fn from(err: crate::Error) -> Self {
        match err {
            crate::Error::NotFound(path) => NavError::NotFound(path),
            crate::Error::NotDirectory(path) => NavError::NotADirectory(path),
            // Note: Path context is lost here. Use from_error_with_path() when path is available.
            crate::Error::Io(io_err) => NavError::Io {
                path: PathBuf::new(),
                source: io_err,
            },
        }
    }
}

// <FILE>crates/fast-fs/src/nav/nav_error.rs</FILE>
// <VERS>END OF VERSION: 0.1.0</VERS>