pub enum Error {
Show 16 variants
Signature(String),
Field(String),
Module(String),
Prediction(String),
Serialization(String),
AssertionFailed {
field: Sym,
description: &'static str,
},
InvalidPattern(String),
Io(Error),
Json(Error),
Utf8(Utf8Error),
Storage(String),
Memory {
operation: &'static str,
reason: String,
suggestion: &'static str,
},
Parse(String),
Validation(String),
Optimization(OptimizationDetails),
Other(String),
}Expand description
Main error type for Kkachi library
Variants§
Signature(String)
Signature-related errors
Field(String)
Field-related errors
Module(String)
Module execution errors
Prediction(String)
Prediction errors
Serialization(String)
Serialization errors
AssertionFailed
Assertion failure
Fields
InvalidPattern(String)
Invalid pattern (regex)
Io(Error)
I/O errors (only with std feature)
Json(Error)
JSON errors
Utf8(Utf8Error)
UTF-8 encoding errors
Storage(String)
Storage errors (DuckDB, etc.)
Memory
Memory store errors with actionable context.
Fields
Parse(String)
Parse errors (for template parsing, etc.)
Validation(String)
Validation errors (for format validation, etc.)
Optimization(OptimizationDetails)
Optimization failure - prompt did not converge.
This is DISTINCT from library errors. Optimization errors are
expected outcomes that can inform the optimization process.
Use Error::is_optimization_error() to check, and
Error::optimization_details() to extract context.
Other(String)
Generic error
Implementations§
Source§impl Error
impl Error
Sourcepub fn memory(
operation: &'static str,
reason: impl Into<String>,
suggestion: &'static str,
) -> Self
pub fn memory( operation: &'static str, reason: impl Into<String>, suggestion: &'static str, ) -> Self
Create a memory error with operation context, reason, and suggestion.
Sourcepub fn prediction(msg: impl Into<String>) -> Self
pub fn prediction(msg: impl Into<String>) -> Self
Create a prediction error
Sourcepub fn validation(msg: impl Into<String>) -> Self
pub fn validation(msg: impl Into<String>) -> Self
Create a validation error
Sourcepub fn optimization(score: f64, iterations: u32, threshold: f64) -> Self
pub fn optimization(score: f64, iterations: u32, threshold: f64) -> Self
Create an optimization error (prompt did not converge).
Use this when optimization fails to meet the threshold, not for library/infrastructure errors.
Sourcepub fn optimization_with_feedback(
score: f64,
iterations: u32,
threshold: f64,
feedback: impl Into<String>,
) -> Self
pub fn optimization_with_feedback( score: f64, iterations: u32, threshold: f64, feedback: impl Into<String>, ) -> Self
Create an optimization error with feedback.
Sourcepub fn is_optimization_error(&self) -> bool
pub fn is_optimization_error(&self) -> bool
Check if this is an optimization error (prompt didn’t converge).
Optimization errors are expected and should inform the optimization process. They are distinct from library errors which indicate bugs or infrastructure issues.
§Example
match result {
Ok(output) => handle_success(output),
Err(e) if e.is_optimization_error() => {
// Use the feedback to improve the prompt
let details = e.optimization_details().unwrap();
improve_prompt(details.feedback.as_deref());
}
Err(e) => {
// This is a library bug - report it
panic!("Library error: {}", e);
}
}Sourcepub fn is_library_error(&self) -> bool
pub fn is_library_error(&self) -> bool
Check if this is a library/infrastructure error (not optimization).
Library errors indicate bugs or configuration issues in kkachi itself, not failures in the optimization process.
Sourcepub fn optimization_details(&self) -> Option<&OptimizationDetails>
pub fn optimization_details(&self) -> Option<&OptimizationDetails>
Get optimization details if this is an optimization error.
Returns None for library errors.
Sourcepub fn optimization_details_mut(&mut self) -> Option<&mut OptimizationDetails>
pub fn optimization_details_mut(&mut self) -> Option<&mut OptimizationDetails>
Get mutable optimization details if this is an optimization error.
Sourcepub fn is_recoverable(&self) -> bool
pub fn is_recoverable(&self) -> bool
Check if this error can be recovered from (optimization errors can).
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
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for Error
impl !RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl !UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more