Crate waddling_errors

Crate waddling_errors 

Source
Expand description

Ultra-minimal diagnostic code system for the Waddling ecosystem

Provides a standardized 4-part diagnostic code format:

Format: SEVERITY.COMPONENT.PRIMARY.SEQUENCE E.CRYPTO.SALT.001

§Quick Start

Define your component and primary enums:

use waddling_errors::prelude::*;

#[derive(Debug, Copy, Clone)]
enum Component { Crypto, Network }

impl ComponentId for Component {
    fn as_str(&self) -> &'static str {
        match self {
            Component::Crypto => "CRYPTO",
            Component::Network => "NETWORK",
        }
    }
}

#[derive(Debug, Copy, Clone)]
enum Primary { Salt, Key, Timeout }

impl PrimaryId for Primary {
    fn as_str(&self) -> &'static str {
        match self {
            Primary::Salt => "SALT",
            Primary::Key => "KEY",
            Primary::Timeout => "TIMEOUT",
        }
    }
}

const ERR_SALT: Code<Component, Primary> = error(Component::Crypto, Primary::Salt, 1);
assert_eq!(ERR_SALT.code(), "E.CRYPTO.SALT.001");

§Sequence Conventions

The Waddling ecosystem uses semantic sequence numbers:

SequenceMeaningExample
001MISSINGRequired item not provided
002MISMATCHValues don’t match expected type
003INVALIDFormat/validation failed
021NOTFOUNDResource not found
025CORRUPTEDData corruption detected
031-897(project)Domain-specific sequences
999COMPLETEFull completion

See docs/SEQUENCE-CONVENTIONS.md for complete list.

§Error Registry Pattern

// errors.rs - Project error registry
use waddling_errors::prelude::*;

#[derive(Debug, Copy, Clone)]
pub enum Component { Crypto, Parse }

impl ComponentId for Component {
    fn as_str(&self) -> &'static str {
        match self {
            Component::Crypto => "CRYPTO",
            Component::Parse => "PARSE",
        }
    }
}

#[derive(Debug, Copy, Clone)]
pub enum Primary { Salt, Length, Depr }

impl PrimaryId for Primary {
    fn as_str(&self) -> &'static str {
        match self {
            Primary::Salt => "SALT",
            Primary::Length => "LENGTH",
            Primary::Depr => "DEPR",
        }
    }
}

pub const SALT_MISSING: Code<Component, Primary> = error(Component::Crypto, Primary::Salt, 1);
pub const KEY_LENGTH: Code<Component, Primary> = error(Component::Crypto, Primary::Length, 2);
pub const DEPRECATED_SYNTAX: Code<Component, Primary> = warning(Component::Parse, Primary::Depr, 1);

Re-exports§

pub use traits::ComponentId;
pub use traits::ComponentIdDocumented;
pub use traits::ErrorMetadata;
pub use traits::FieldMeta;
pub use traits::PrimaryId;
pub use traits::PrimaryIdDocumented;
pub use traits::Role;

Modules§

prelude
Commonly used types and functions
traits
Trait-based extensibility for error code components and primaries

Structs§

Code
Waddling diagnostic code: SEVERITY.COMPONENT.PRIMARY.SEQUENCE

Enums§

Severity
Diagnostic severity level (single-character prefix for 4-part codes)

Functions§

blocked
Create a blocked code
completed
Create a completed code
critical
Create a critical code
error
Create an error code
help
Create a help code
info
Create an info code
success
Create a success code
trace
Create a trace code
warning
Create a warning code