golem_rib_repl/
repl_bootstrap_error.rs

1use std::fmt::{Display, Formatter};
2
3/// Represents errors that can occur during the bootstrap phase of the Rib REPL environment.
4#[derive(Debug, Clone, PartialEq)]
5pub enum ReplBootstrapError {
6    /// Multiple components were found, but the REPL requires a single component context.
7    ///
8    /// To resolve this, either:
9    /// - Ensure the context includes only one component, or
10    /// - Explicitly specify the component to load when starting the REPL.
11    ///
12    /// In the future, Rib will support multiple components
13    MultipleComponentsFound(String),
14
15    /// No components were found in the given context.
16    NoComponentsFound,
17
18    /// Failed to load a specified component.
19    ComponentLoadError(String),
20
21    /// Failed to read from or write to the REPL history file.
22    ReplHistoryFileError(String),
23}
24
25impl std::error::Error for ReplBootstrapError {}
26
27impl Display for ReplBootstrapError {
28    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
29        match self {
30            ReplBootstrapError::MultipleComponentsFound(msg) => {
31                write!(f, "Multiple components found: {msg}")
32            }
33            ReplBootstrapError::NoComponentsFound => {
34                write!(f, "No components found in the given context")
35            }
36            ReplBootstrapError::ComponentLoadError(msg) => {
37                write!(f, "Failed to load component: {msg}")
38            }
39            ReplBootstrapError::ReplHistoryFileError(msg) => {
40                write!(f, "Failed to read/write REPL history file: {msg}")
41            }
42        }
43    }
44}