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 Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<&str> for Error
Implements conversion from &str to Error::Configuration.
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§impl From<RecvError> for Error
Implements conversion from tokio::sync::oneshot::error::RecvError to Error::ChannelReceive.
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§impl<T> From<SendError<T>> for Error
Implements conversion from tokio::sync::mpsc::error::SendError<T> to Error::ChannelSend.
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§impl From<String> for Error
Implements conversion from String to Error::Configuration.
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§impl From<TryRecvError> for Error
Implements conversion from tokio::sync::mpsc::error::TryRecvError to Error::ChannelReceive.
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
fn from(_: TryRecvError) -> Self
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.
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(())
}