Enum Errata

Source
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 only
  • Two: Error reason and the problematic formula or expression
  • Three: 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

Fields

§reason: String
§

Two

Error with reason and formula context

Fields

§reason: String
§formula: String
§

Three

Full diagnostic error with reason, formula, and location

Fields

§reason: String
§formula: String
§location: String

Implementations§

Source§

impl Errata

Source

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(_)));
Source

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 description
  • formula - 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(_)));
Source

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 description
  • formula - The problematic formula or expression
  • location - 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(_)));
Source

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 description
  • expression - 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(_)));
Source

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 description
  • expression - The problematic expression
  • location - 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(_)));
Source

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");
Source

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");
Source

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 Clone for Errata

Source§

fn clone(&self) -> Errata

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Errata

Source§

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

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

impl Display for Errata

Source§

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

Source§

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)

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

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

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");
Source§

impl PartialEq for Errata

Source§

fn eq(&self, other: &Errata) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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
§

impl<T> ToStringFallible for T
where T: Display,

§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,