Skip to main content

ErrorCode

Struct ErrorCode 

Source
pub struct ErrorCode { /* private fields */ }
Expand description

An error code with namespace, numeric code, and operation category.

Error codes follow the format E-XXX-YYY where:

  • XXX is the namespace (CORE, CFG, IO, etc.)
  • YYY is the numeric code (001-999)

§Compile-time Guarantees

All error codes are defined as const statics, providing:

  • Namespace frozen at compile time (cannot be constructed at runtime)
  • Code range validated (001-999)
  • Impact score validated (0-1000)
  • Category compatibility enforced
  • Severity authority enforced (strict_severity mode)

§Construction APIs

  • const_new: For const statics (panics = compile error)
  • checked_new: For runtime construction (returns Result, never panics)

§No-Copy/No-Clone Semantics

This type is part of the error identity layer and cannot be copied, cloned, or moved after const initialization. All usage is by reference.

§Zero-Allocation Guarantee

All operations are zero-allocation. Display writes directly to formatter.

§Example

use palisade_errors::{ErrorCode, OperationCategory, ImpactScore, define_error_codes, namespaces};

// Compile-time construction (panics if invalid)
const CFG_PARSE_FAILED: ErrorCode = ErrorCode::const_new(
    &namespaces::CFG,
    100,
    OperationCategory::Configuration,
    ImpactScore::new(700)
);
 
// Runtime construction (returns Result)
let code = ErrorCode::checked_new(
    &namespaces::IO,
    code_from_config,
    OperationCategory::IO,
    ImpactScore::checked_new(impact_from_config).unwrap()
).unwrap();
 
// Use by reference only
fn log_error(code: &ErrorCode) {
    println!("Error: {}", code);
}
 
log_error(&CFG_PARSE_FAILED);

Implementations§

Source§

impl ErrorCode

Source

pub const fn const_new( namespace: &'static ErrorNamespace, code: u16, category: OperationCategory, impact: ImpactScore, ) -> Self

Create a new error code with compile-time validation (infallible in const contexts).

§Panics

Panics if:

  • Code is 0 or >= 1000 (must be 001-999)
  • Category is not permitted for the namespace
  • Impact is not permitted for the namespace (strict_severity mode)

In const contexts, panics occur at compile time. In runtime contexts, panics occur at runtime.

§Use Case

For const static error code definitions where all values are known at compile time and violations indicate programmer error.

Source

pub fn checked_new( namespace: &'static ErrorNamespace, code: u16, category: OperationCategory, impact: ImpactScore, ) -> Result<Self, InternalErrorCodeViolation>

Create a new error code with runtime validation (fallible, no panics).

§Errors

Returns Err with internal violation details. For external contexts, call .to_public() on the error to sanitize taxonomy information.

§Use Case

For runtime construction from untrusted sources (config, plugins, etc.).

Source

pub const fn category(&self) -> OperationCategory

Get the operation category.

Source

pub const fn namespace(&self) -> &'static ErrorNamespace

Get namespace reference.

Source

pub const fn code(&self) -> u16

Get numeric code.

Source

pub const fn impact(&self) -> ImpactScore

Get impact score.

Source

pub const fn impact_level(&self) -> ErrorImpact

Get the detailed impact level.

Trait Implementations§

Source§

impl Debug for ErrorCode

Source§

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

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

impl Display for ErrorCode

Source§

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

Zero-allocation formatting - writes directly to formatter.

Source§

impl Hash for ErrorCode

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ErrorCode

Source§

fn eq(&self, other: &ErrorCode) -> 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 Eq for ErrorCode

Source§

impl StructuralPartialEq for ErrorCode

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

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