Module error

Module error 

Source
Expand description

Error types and handling. Error types for bubbletea-rs.

This module defines the custom error types used throughout the bubbletea-rs library. All errors are unified under the Error enum, providing a consistent way to handle various failure conditions, from I/O issues to program-specific panics.

§Error Handling Philosophy

The bubbletea-rs library follows Rust’s idiomatic error handling patterns. All fallible operations return Result<T, Error> where Error is the main error type defined in this module. The library uses the thiserror crate to provide clear error messages and convenient error conversions.

§Common Usage Patterns

§Basic Error Handling

use bubbletea_rs::{Program, Model, Msg, Error, Cmd};

async fn run_program() -> Result<(), Error> {
    let program = Program::<MyModel>::builder().build()?;
    program.run().await?;
    Ok(())
}

§Pattern Matching on Errors

use bubbletea_rs::Error;

fn handle_error(err: Error) {
    match err {
        Error::Interrupted => {
            println!("Program was interrupted by user");
        }
        Error::ProgramKilled => {
            println!("Program was explicitly killed");
        }
        Error::Io(io_err) => {
            eprintln!("I/O error occurred: {}", io_err);
        }
        _ => {
            eprintln!("Unexpected error: {}", err);
        }
    }
}

§Converting Between Error Types

The library provides automatic conversions from common error types:

use bubbletea_rs::Error;
use std::io;

fn io_operation() -> Result<String, Error> {
    // std::io::Error is automatically converted to Error::Io
    let contents = std::fs::read_to_string("file.txt")?;
    Ok(contents)
}

Enums§

Error
The main error type for bubbletea-rs operations.