nanorust 0.1.0

A terminal-based text editor written in Rust, inspired by GNU nano
Documentation
//! Error types for the nano rust editor.
//!
//! This module defines all error types that can occur during editor operations,
//! including I/O errors, terminal errors, file errors, and parsing errors.

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

/// Custom result type for the editor.
///
/// This is a convenience type alias that uses [`EditorError`] as the error type.
pub type Result<T> = std::result::Result<T, EditorError>;

/// Error types for the nano rust editor.
///
/// This enum represents all possible errors that can occur during editor operations.
/// It uses the `thiserror` crate for automatic `Error` trait implementation and
/// display formatting.
#[derive(Error, Debug)]
pub enum EditorError {
    /// An I/O error occurred.
    ///
    /// This variant automatically converts from `std::io::Error` using the `From` trait.
    #[error("IO error: {0}")]
    IoError(#[from] io::Error),

    /// A terminal-related error occurred.
    ///
    /// This includes errors from terminal initialization, raw mode operations,
    /// or terminal size queries.
    #[error("Terminal error: {0}")]
    TerminalError(String),

    /// The specified file was not found.
    ///
    /// Contains the path to the file that could not be found.
    #[error("File not found: {0}")]
    FileNotFound(PathBuf),

    /// Permission was denied when accessing a file.
    ///
    /// Contains the path to the file that could not be accessed.
    #[error("Permission denied: {0}")]
    PermissionDenied(PathBuf),

    /// Invalid UTF-8 encoding was encountered.
    ///
    /// This occurs when reading files or input that contains invalid UTF-8 sequences.
    #[error("Invalid UTF-8 encoding")]
    InvalidUtf8,

    /// A buffer-related error occurred.
    ///
    /// This includes errors from buffer operations like saving without a filename.
    #[error("Buffer error: {0}")]
    BufferError(String),

    /// A parsing error occurred.
    ///
    /// This includes errors from parsing user input like line numbers or commands.
    #[error("Parse error: {0}")]
    ParseError(String),

    /// A configuration error occurred.
    ///
    /// This includes errors from parsing command-line arguments or configuration files.
    #[error("Configuration error: {0}")]
    ConfigError(String),
}