alma 0.1.1

A Bevy-native modal text editor with Vim-style navigation.
Documentation
//! Error taxonomy for buffer opening and persistence.

use crate::{
    fs_utils::{EscapedDisplayText, FileReadError, FileWriteError},
    text_stream::TextStreamError,
};
use std::path::PathBuf;

/// Errors that can occur while opening the initial buffer.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum BufferOpenError {
    /// The requested path failed filesystem policy or bounded file reading.
    #[error("{0}")]
    File(#[from] FileReadError),
    /// The requested file is not valid UTF-8.
    #[error("{} is not valid editor text: {source}", EscapedDisplayText::from_path(path).as_str())]
    Text {
        /// Path containing invalid text bytes.
        path: PathBuf,
        /// Underlying text stream error.
        #[source]
        source: TextStreamError,
    },
}

/// Errors that can occur while writing the current buffer.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum BufferWriteError {
    /// The buffer has no path to write to.
    #[error("buffer has no file name")]
    NoFileName,
    /// The backing file failed filesystem policy or atomic persistence.
    #[error("{0}")]
    File(#[from] FileWriteError),
}