Crate waddling_errors

Crate waddling_errors 

Source
Expand description

Ultra-minimal diagnostic code system for the Waddling ecosystem

This crate provides a standardized 4-part diagnostic code format:

Format: SEVERITY.COMPONENT.PRIMARY.SEQUENCEE.CRYPTO.SALT.001

§Quick Start

use waddling_errors::prelude::*;

// Ergonomic convenience functions
const ERR_SALT: Code = error("CRYPTO", "SALT", 1);

assert_eq!(ERR_SALT.code(), "E.CRYPTO.SALT.001");

§Alternative API Styles

use waddling_errors::{Code, Severity};

// Method style
const ERR: Code = Code::error("CRYPTO", "SALT", 1);

// Explicit severity
const WARN: Code = Code::new(Severity::Warning, "CRYPTO", "WEAK", 1);

§Sequence Conventions

The Waddling ecosystem uses semantic sequence numbers for common error patterns:

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

Benefits: .001 always means “missing” across ALL Waddling projects, enabling instant recognition and cross-project consistency.

use waddling_errors::prelude::*;

// Following conventions (recommended)
const ERR_MISSING_SALT: Code = error("CRYPTO", "SALT", 1);  // .001 = MISSING

const ERR_LENGTH_MISMATCH: Code = error("CRYPTO", "LENGTH", 2);  // .002 = MISMATCH

// Domain-specific (031-897 range for project logic)
const ERR_HMAC_COMPUTE: Code = error("CRYPTO", "HMAC", 31);

These conventions are SHOULD guidelines (RFC 2119), not requirements. See repository docs/SEQUENCE-CONVENTIONS.md for complete list and enforcement strategies.

§Error Registry Pattern

For larger projects, create a central registry:

// errors.rs - Your project's error registry
pub mod errors {
    use waddling_errors::prelude::*;
     
    // Crypto errors (E.CRYPTO.*)
    pub const SALT_MISSING: Code = error("CRYPTO", "SALT", 1);
    pub const KEY_LENGTH: Code = error("CRYPTO", "LENGTH", 2);
    pub const HMAC_INVALID: Code = error("CRYPTO", "HMAC", 3);
     
    // Parser warnings (W.PARSE.*)
    pub const DEPRECATED_SYNTAX: Code = warning("PARSE", "DEPR", 1);
}

Modules§

prelude
Prelude module for convenient imports

Structs§

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

Enums§

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

Functions§

blocked
Create a blocked code (B)
completed
Create a completed code (K)
critical
Create a critical code (C)
error
Create an error code (E)
info
Create an info code (I)
success
Create a success code (S)
trace
Create a trace code (T)
warning
Create a warning code (W)

Type Aliases§

DiagnosticCode
Backward compatibility alias for Code
ErrorCode
Backward compatibility alias for Code