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 success(component: &'static str, primary: &'static str, sequence: u16) -> Code {
82 Code::success(component, primary, sequence)
83}
84
85pub const fn completed(component: &'static str, primary: &'static str, sequence: u16) -> Code {
86 Code::completed(component, primary, sequence)
87}
88
89pub const fn info(component: &'static str, primary: &'static str, sequence: u16) -> Code {
90 Code::info(component, primary, sequence)
91}
92
93pub const fn trace(component: &'static str, primary: &'static str, sequence: u16) -> Code {
94 Code::trace(component, primary, sequence)
95}
96
97// Prelude module
98
99pub mod prelude {
100 pub use crate::{Code, Severity};
101 pub use crate::{blocked, completed, critical, error, info, success, trace, warning};
102}
103
104// Backward compatibility
105
106pub type ErrorCode = Code;
107pub type DiagnosticCode = Code;