waddling_errors/
lib.rs

1//! Ultra-minimal diagnostic code system for the Waddling ecosystem
2//!
3//! Provides a standardized 4-part diagnostic code format:
4//!
5//! **Format**: `SEVERITY.COMPONENT.PRIMARY.SEQUENCE`  `E.CRYPTO.SALT.001`
6//!
7//! # Quick Start
8//!
9//! ```rust
10//! use waddling_errors::prelude::*;
11//!
12//! const ERR_SALT: Code = error("CRYPTO", "SALT", 1);
13//! assert_eq!(ERR_SALT.code(), "E.CRYPTO.SALT.001");
14//! ```
15//!
16//! # Sequence Conventions
17//!
18//! The Waddling ecosystem uses semantic sequence numbers:
19//!
20//! | Sequence | Meaning    | Example                           |
21//! |----------|------------|-----------------------------------|
22//! | 001      | MISSING    | Required item not provided        |
23//! | 002      | MISMATCH   | Values don't match expected type  |
24//! | 003      | INVALID    | Format/validation failed          |
25//! | 021      | NOTFOUND   | Resource not found                |
26//! | 025      | CORRUPTED  | Data corruption detected          |
27//! | 031-897  | (project)  | Domain-specific sequences         |
28//! | 999      | COMPLETE   | Full completion                   |
29//!
30//! See `docs/SEQUENCE-CONVENTIONS.md` for complete list.
31//!
32//! # Error Registry Pattern
33//!
34//! ```rust
35//! // errors.rs - Project error registry
36//! pub mod errors {
37//!     use waddling_errors::prelude::*;
38//!     
39//!     pub const SALT_MISSING: Code = error("CRYPTO", "SALT", 1);
40//!     pub const KEY_LENGTH: Code = error("CRYPTO", "LENGTH", 2);
41//!     pub const DEPRECATED_SYNTAX: Code = warning("PARSE", "DEPR", 1);
42//! }
43//! ```
44
45#![no_std]
46#![forbid(unsafe_code)]
47
48#[cfg(feature = "std")]
49extern crate std;
50
51#[cfg(not(feature = "std"))]
52extern crate alloc;
53
54mod code;
55mod severity;
56
57#[cfg(feature = "hash")]
58pub(crate) mod hash;
59
60pub use code::Code;
61pub use severity::Severity;
62
63// Top-level convenience functions
64
65pub const fn error(component: &'static str, primary: &'static str, sequence: u16) -> Code {
66    Code::error(component, primary, sequence)
67}
68
69pub const fn warning(component: &'static str, primary: &'static str, sequence: u16) -> Code {
70    Code::warning(component, primary, sequence)
71}
72
73pub const fn critical(component: &'static str, primary: &'static str, sequence: u16) -> Code {
74    Code::critical(component, primary, sequence)
75}
76
77pub const fn blocked(component: &'static str, primary: &'static str, sequence: u16) -> Code {
78    Code::blocked(component, primary, sequence)
79}
80
81pub const fn help(component: &'static str, primary: &'static str, sequence: u16) -> Code {
82    Code::help(component, primary, sequence)
83}
84
85pub const fn success(component: &'static str, primary: &'static str, sequence: u16) -> Code {
86    Code::success(component, primary, sequence)
87}
88
89pub const fn completed(component: &'static str, primary: &'static str, sequence: u16) -> Code {
90    Code::completed(component, primary, sequence)
91}
92
93pub const fn info(component: &'static str, primary: &'static str, sequence: u16) -> Code {
94    Code::info(component, primary, sequence)
95}
96
97pub const fn trace(component: &'static str, primary: &'static str, sequence: u16) -> Code {
98    Code::trace(component, primary, sequence)
99}
100
101// Prelude module
102
103pub mod prelude {
104    pub use crate::{Code, Severity};
105    pub use crate::{blocked, completed, critical, error, info, success, trace, warning};
106}
107
108// Backward compatibility
109
110pub type ErrorCode = Code;
111pub type DiagnosticCode = Code;