Error

Enum Error 

Source
pub enum Error {
    ProgramPanic(String),
    ProgramKilled,
    Interrupted,
    Io(Error),
    Terminal(String),
    ChannelSend,
    ChannelReceive,
    Configuration(String),
    CommandExecution(String),
    SendError,
    ChannelFull,
    ChannelClosed,
}
Expand description

The main error type for bubbletea-rs operations.

This enum encapsulates all possible errors that can occur within the library, providing detailed information about the cause of the error.

§Examples

§Creating errors manually

use bubbletea_rs::Error;

// Create a configuration error
let err = Error::Configuration("Invalid input device".to_string());

// Create a program panic error
let panic_err = Error::ProgramPanic("Model update failed".to_string());

§Working with Results

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

fn create_program() -> Result<Program<MyModel>, Error> {
    Program::<MyModel>::builder().build()
}

Variants§

§

ProgramPanic(String)

Represents a program panic, similar to Go’s ErrProgramPanic. This error is typically caught by the Program and indicates an unrecoverable error within the model’s update or view methods.

§

ProgramKilled

Indicates that the program was explicitly killed, similar to Go’s ErrProgramKilled. This can happen if the kill() method is called on the Program.

§

Interrupted

Indicates that the program was interrupted, similar to Go’s ErrInterrupted. This typically occurs when an interrupt signal (e.g., Ctrl+C) is received.

§

Io(Error)

Represents an I/O error, wrapping std::io::Error. This can occur during terminal operations, file access, or network communication.

§

Terminal(String)

Represents an error specifically related to terminal operations. This can include issues with raw mode, alternate screen, or cursor manipulation.

§

ChannelSend

Indicates a failure when sending a message through an MPSC channel. This usually means the receiving end of the channel has been dropped.

§

ChannelReceive

Indicates a failure when receiving a message from an MPSC channel. This usually means the sending end of the channel has been dropped.

§

Configuration(String)

Represents a configuration error, typically from the ProgramBuilder. This can occur if invalid or inconsistent configuration options are provided.

§

CommandExecution(String)

Represents an error during the execution of a command. This can include failures when spawning external processes or issues with command output.

§

SendError

Represents a generic send error, used when a message fails to be sent.

§

ChannelFull

Bounded channel is full (backpressure). The message could not be enqueued.

§

ChannelClosed

Channel is closed; no receivers (or senders) are available.

Trait Implementations§

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<&str> for Error

Implements conversion from &str to Error::Configuration.

This provides a convenient way to create configuration errors from string slices.

§Examples

use bubbletea_rs::Error;

fn check_name(name: &str) -> Result<(), Error> {
    if name.is_empty() {
        return Err("Name cannot be empty".into());
    }
    Ok(())
}
Source§

fn from(msg: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<RecvError> for Error

Implements conversion from tokio::sync::oneshot::error::RecvError to Error::ChannelReceive.

This allows ? operator to be used with Tokio Oneshot receive operations.

§Examples

use bubbletea_rs::Error;
use tokio::sync::oneshot;

async fn receive_once(receiver: oneshot::Receiver<String>) -> Result<String, Error> {
    // The ? operator automatically converts RecvError to Error::ChannelReceive
    let value = receiver.await?;
    Ok(value)
}
Source§

fn from(_: RecvError) -> Self

Converts to this type from the input type.
Source§

impl<T> From<SendError<T>> for Error

Implements conversion from tokio::sync::mpsc::error::SendError<T> to Error::ChannelSend.

This allows ? operator to be used with Tokio MPSC send operations, making error propagation seamless when working with channels.

§Examples

use bubbletea_rs::{Error, Msg};
use tokio::sync::mpsc;

async fn send_message(sender: mpsc::Sender<Msg>, msg: Msg) -> Result<(), Error> {
    // The ? operator automatically converts SendError to Error::ChannelSend
    sender.send(msg).await?;
    Ok(())
}
Source§

fn from(_: SendError<T>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Error

Implements conversion from String to Error::Configuration.

This provides a convenient way to create configuration errors from string messages.

§Examples

use bubbletea_rs::Error;

fn validate_config(value: u32) -> Result<(), Error> {
    if value > 100 {
        return Err(format!("Value {} exceeds maximum of 100", value).into());
    }
    Ok(())
}
Source§

fn from(msg: String) -> Self

Converts to this type from the input type.
Source§

impl From<TryRecvError> for Error

Implements conversion from tokio::sync::mpsc::error::TryRecvError to Error::ChannelReceive.

This allows ? operator to be used with Tokio MPSC try_recv operations.

§Examples

use bubbletea_rs::{Error, Msg};
use tokio::sync::mpsc;

fn try_receive(receiver: &mut mpsc::Receiver<Msg>) -> Result<Option<Msg>, Error> {
    // The ? operator automatically converts TryRecvError to Error::ChannelReceive
    match receiver.try_recv() {
        Ok(msg) => Ok(Some(msg)),
        Err(mpsc::error::TryRecvError::Empty) => Ok(None),
        Err(e) => Err(e.into()), // Converts to Error::ChannelReceive
    }
}
Source§

fn from(_: TryRecvError) -> Self

Converts to this type from the input type.
Source§

impl<T> From<TrySendError<T>> for Error

Implements conversion from tokio::sync::mpsc::error::TrySendError<T> to channel-related errors that preserve whether the channel was full or closed.

This conversion distinguishes between ChannelFull (backpressure) and ChannelClosed errors, providing more specific error information than the generic ChannelSend.

§Examples

use bubbletea_rs::{Error, Msg};
use tokio::sync::mpsc;

fn try_send(sender: &mpsc::Sender<Msg>, msg: Msg) -> Result<(), Error> {
    // Automatically converts to Error::ChannelFull or Error::ChannelClosed
    sender.try_send(msg)?;
    Ok(())
}
Source§

fn from(err: TrySendError<T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl !UnwindSafe for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.