pub enum Errata {
One {
reason: String,
},
Two {
reason: String,
formula: String,
},
Three {
reason: String,
formula: String,
location: String,
},
}Expand description
Represents expression and evaluation errors with varying levels of detail.
The Errata enum captures error information at different diagnostic levels:
One: Basic error reason onlyTwo: Error reason and the problematic formula or expressionThree: Full diagnostic information including reason, formula, and location
This enum is used throughout the AIMX expression engine to provide detailed error information that helps users understand what went wrong and where the error occurred in their expressions.
§Examples
Creating different levels of error information:
use aimx::values::Errata;
// Basic error with just a reason
let basic_error = Errata::One { reason: "Syntax Error".to_string() };
// Error with formula context
let formula_error = Errata::Two {
reason: "Division by zero".to_string(),
formula: "10 / 0".to_string(),
};
// Full diagnostic error
let diagnostic_error = Errata::Three {
reason: "Unexpected token".to_string(),
formula: "1 + * 2".to_string(),
location: "* 2".to_string(),
};§Display Format
When displayed, Errata produces formatted output showing:
- The error reason
- The problematic formula or expression
- Location indicators (arrows pointing to the problematic area)
Example output for a diagnostic error:
Unexpected token
1 + * 2
^Variants§
One
Basic error with only a reason
Two
Error with reason and formula context
Three
Full diagnostic error with reason, formula, and location
Implementations§
Source§impl Errata
impl Errata
Sourcepub fn new_reason(reason: String) -> Value
pub fn new_reason(reason: String) -> Value
Creates a new Value::Errata with only a reason.
This is the simplest form of error representation, containing only the error message without additional context.
§Arguments
reason- The error message or description
§Returns
Returns a Value::Errata containing the basic error information.
§Examples
use aimx::{Value, values::Errata};
let error_value = Errata::new_reason("Syntax Error".to_string());
assert!(matches!(error_value, Value::Errata(_)));Sourcepub fn new_reason_formula(reason: String, formula: String) -> Value
pub fn new_reason_formula(reason: String, formula: String) -> Value
Creates a new Value::Errata with a reason and formula context.
This provides more context by including the problematic formula along with the error message.
§Arguments
reason- The error message or descriptionformula- The problematic formula or expression
§Returns
Returns a Value::Errata containing the error with formula context.
§Examples
use aimx::{Value, values::Errata};
let error_value = Errata::new_reason_formula(
"Division by zero".to_string(),
"10 / 0".to_string()
);
assert!(matches!(error_value, Value::Errata(_)));Sourcepub fn new_reason_formula_location(
reason: String,
formula: String,
location: String,
) -> Value
pub fn new_reason_formula_location( reason: String, formula: String, location: String, ) -> Value
Creates a new Value::Errata with full diagnostic information.
This provides the most detailed error information including the reason, the problematic formula, and the specific location within the formula.
§Arguments
reason- The error message or descriptionformula- The problematic formula or expressionlocation- The specific location within the formula where the error occurred
§Returns
Returns a Value::Errata containing full diagnostic error information.
§Examples
use aimx::{Value, values::Errata};
let error_value = Errata::new_reason_formula_location(
"Unexpected token".to_string(),
"1 + * 2".to_string(),
"* 2".to_string()
);
assert!(matches!(error_value, Value::Errata(_)));Sourcepub fn new_reason_expression(reason: String, expression: String) -> Expression
pub fn new_reason_expression(reason: String, expression: String) -> Expression
Creates a new Expression::Errata with a reason and expression context.
This is similar to new_reason_formula but creates an Expression variant
instead of a Value variant.
§Arguments
reason- The error message or descriptionexpression- The problematic expression
§Returns
Returns an Expression::Errata containing the error with expression context.
§Examples
use aimx::{Expression, values::Errata};
let error_expression = Errata::new_reason_expression(
"Undefined variable".to_string(),
"undefined_var".to_string()
);
assert!(matches!(error_expression, Expression::Errata(_)));Sourcepub fn new_reason_expression_location(
reason: String,
expression: String,
location: String,
) -> Expression
pub fn new_reason_expression_location( reason: String, expression: String, location: String, ) -> Expression
Creates a new Expression::Errata with full diagnostic information.
This provides the most detailed error information for expression errors, including the reason, the problematic expression, and the specific location.
§Arguments
reason- The error message or descriptionexpression- The problematic expressionlocation- The specific location within the expression where the error occurred
§Returns
Returns an Expression::Errata containing full diagnostic error information.
§Examples
use aimx::{Expression, values::Errata};
let error_expression = Errata::new_reason_expression_location(
"Syntax error".to_string(),
"1 + ".to_string(),
"+ ".to_string()
);
assert!(matches!(error_expression, Expression::Errata(_)));Sourcepub fn reason(&self) -> &str
pub fn reason(&self) -> &str
Returns the error reason string.
This method extracts the error message from any Errata variant.
§Returns
Returns a string slice containing the error reason.
§Examples
use aimx::values::Errata;
let errata = Errata::One { reason: "Syntax Error".to_string() };
assert_eq!(errata.reason(), "Syntax Error");Sourcepub fn formula(&self) -> &str
pub fn formula(&self) -> &str
Returns the problematic formula or expression.
For Errata::Two and Errata::Three variants, returns the formula
that caused the error. For Errata::One, returns an empty string.
§Returns
Returns a string slice containing the problematic formula.
§Examples
use aimx::values::Errata;
let errata = Errata::Two {
reason: "Division by zero".to_string(),
formula: "10 / 0".to_string(),
};
assert_eq!(errata.formula(), "10 / 0");Sourcepub fn location(&self) -> &str
pub fn location(&self) -> &str
Returns the specific location within the formula where the error occurred.
Only Errata::Three variants contain location information.
For other variants, returns an empty string.
§Returns
Returns a string slice containing the error location.
§Examples
use aimx::values::Errata;
let errata = Errata::Three {
reason: "Unexpected token".to_string(),
formula: "1 + * 2".to_string(),
location: "* 2".to_string(),
};
assert_eq!(errata.location(), "* 2");Trait Implementations§
Source§impl Display for Errata
impl Display for Errata
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the error for display using the default string representation.
This implementation uses the stringizer writer mode to produce a human-readable representation of the error, including the reason, formula, and location indicators.
§Arguments
f- The formatter to write to
§Returns
A fmt::Result indicating success or failure of the formatting operation.
§Examples
use aimx::values::Errata;
let errata = Errata::Three {
reason: "Unexpected token".to_string(),
formula: "1 + * 2".to_string(),
location: "* 2".to_string(),
};
let display_string = format!("{}", errata);
assert!(display_string.contains("Unexpected token"));
assert!(display_string.contains("1 + * 2"));
assert!(display_string.contains("^"));Source§impl ExpressionLike for Errata
impl ExpressionLike for Errata
Source§fn evaluate(&self, _context: &mut dyn ContextLike) -> Result<Value>
fn evaluate(&self, _context: &mut dyn ContextLike) -> Result<Value>
Evaluates the error expression, returning the error as a value.
Since Errata represents error information rather than an evaluatable
expression, this method simply returns the error wrapped in a Value::Errata.
§Arguments
_context- The evaluation context (unused for errors)
§Returns
Returns Ok(Value::Errata(self.clone())) containing the error information.
§Examples
use aimx::{values::Errata, ExpressionLike, Context};
let errata = Errata::One { reason: "Test error".to_string() };
let mut context = Context::new();
let result = errata.evaluate(&mut context).unwrap();
assert!(matches!(result, aimx::Value::Errata(_)));Source§fn write(&self, writer: &mut Writer)
fn write(&self, writer: &mut Writer)
Writes the error information to the provided writer.
This method delegates to the writer’s print_errata method to format
the error information according to the writer’s mode (string, sanitized, formula).
§Arguments
writer- The writer to write the error information to
§Examples
use aimx::{values::Errata, ExpressionLike, Writer};
let errata = Errata::Two {
reason: "Division by zero".to_string(),
formula: "10 / 0".to_string(),
};
let mut writer = Writer::stringizer();
errata.write(&mut writer);
let output = writer.finish();
assert!(output.contains("Division by zero"));
assert!(output.contains("10 / 0"));Source§fn to_sanitized(&self) -> String
fn to_sanitized(&self) -> String
Converts the error to a sanitized string representation.
This method produces a string with special characters escaped, making it safe for JSON-compatible or safely quoted output.
§Returns
Returns a sanitized string representation of the error.
§Examples
use aimx::{values::Errata, ExpressionLike};
let errata = Errata::One { reason: "Error <message>".to_string() };
let sanitized = errata.to_sanitized();
assert!(sanitized.contains("Error <message>"));Source§fn to_formula(&self) -> String
fn to_formula(&self) -> String
Converts the error to a formula string representation.
This method produces a string with proper quoting and escaping
for use in formulas. For Errata, this typically returns just
the original formula or expression that caused the error.
§Returns
Returns a formula string representation of the error.
§Examples
use aimx::{values::Errata, ExpressionLike};
let errata = Errata::Two {
reason: "Division by zero".to_string(),
formula: "10 / 0".to_string(),
};
let formula = errata.to_formula();
assert_eq!(formula, "10 / 0");impl StructuralPartialEq for Errata
Auto Trait Implementations§
impl Freeze for Errata
impl RefUnwindSafe for Errata
impl Send for Errata
impl Sync for Errata
impl Unpin for Errata
impl UnwindSafe for Errata
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.