waddling-errors đĻ
Ultra-minimal diagnostic code system
Overview
waddling-errors provides a super ergonomic diagnostic code system with consistent error code format generation.
Key Features
- â Tiny - Modular design, only include what you need
- â Zero dependencies by default - Optional features for extended functionality
- â
Semantic methods -
is_blocking(),is_positive(),priority(), etc. - â Visual representation - Emojis (đĨâ ī¸â ) and ANSI colors for terminal UIs
- â Serialization - Optional Serde support for JSON/etc.
- â
no_stdcompatible - Works in embedded and WASM environments - â Const-friendly - Error codes can be defined as constants
Why This Exists
Projects need consistent error code formats for diagnostic tooling integration.
Standard Format
4-Part Format - consistent diagnostic codes:
SEVERITY.COMPONENT.PRIMARY.SEQUENCE â E.CRYPTO.SALT.001
Where SEVERITY can be:
| Severity | Code | Emoji | Use Case |
|---|---|---|---|
| Error | E |
â | Invalid input, logic errors |
| Warning | W |
â ī¸ | Deprecated API, edge cases |
| Critical | C |
đĨ | Data corruption, security breach |
| Blocked | B |
đĢ | Deadlock, I/O wait, network down |
| Success | S |
â | Operation succeeded |
| Completed | K |
âī¸ | Task/phase finished |
| Info | I |
âšī¸ | Events, milestones, status |
| Trace | T |
đ | Execution traces, probes, timing |
Solution: waddling-errors provides a single, minimal, flexible implementation.
Installation
Add to your Cargo.toml:
[]
# Minimal (no optional features)
= { = "0.1", = false }
# With base62 hashing
= { = "0.1", = ["hash"] }
# With ANSI terminal colors
= { = "0.1", = ["ansi-colors"] }
# With emoji support
= { = "0.1", = ["emoji"] }
# With Serde serialization
= { = "0.1", = ["serde"] }
# All features
= { = "0.1", = ["hash", "ansi-colors", "emoji", "serde"] }
Quick Start
use *;
// Ultra-clean error definitions
const ERR_SALT: Code = error;
const WARN_DEPRECATED: Code = warning;
const SUCCESS_BUILD: Code = success;
Usage Patterns
waddling-errors provides multiple API styles - choose what fits your project:
1. Convenience Functions (Recommended)
The cleanest, most ergonomic approach:
use *;
// All 8 severity levels
const ERR: Code = error;
const WARN: Code = warning;
const CRIT: Code = critical;
const BLOCK: Code = blocked;
const SUCCESS: Code = success;
const COMPLETE: Code = completed;
const INFO: Code = info;
const TRACE: Code = trace;
2. Method Style
Object-oriented approach:
use Code;
const ERR: Code = error;
const WARN: Code = warning;
3. Explicit Severity
Full control when needed:
use ;
const ERR: Code = new;
Standalone Usage (No Dependencies)
Return diagnostic codes directly:
use *;
const ERR_INVALID_SALT: Code = error;
// Or wrap in your own error type
See examples/standalone.rs for a complete example with no external dependencies.
Error Registry Pattern (Recommended)
For larger projects, create a central error registry:
// errors.rs - Your project's error registry
// Use across your project
use SALT_MISSING;
Benefits:
- â Centralized error definitions
- â Easy to document and maintain
- â Prevents duplicate sequence numbers
- â IDE autocomplete for all error codes
Semantic Methods
Severity provides rich semantic methods for intelligent error handling:
Categorization
use Severity;
// Check if execution should stop
if severity.is_blocking
// Categorize outcomes
if severity.is_positive else if severity.is_negative else
Priority Ordering
use Severity;
// Sort diagnostics by priority (0=lowest, 7=highest)
diagnostics.sort_by_key;
// Filter by severity level
let critical_issues: = diagnostics
.iter
.filter
.collect;
Metadata
use Severity;
let sev = Error;
println!; // "E"
println!; // "Error"
println!; // "Operation failed"
println!; // 7
Visual Representation
Emojis (Feature Flag)
Perfect for modern terminal UIs and logs (requires emoji feature):
use *;
println!;
// Output: â Build failed!
println!;
// Output: â ī¸ Warning: deprecated API
println!;
// Output: â
All tests passed!
Full emoji set:
- â Error
- đĢ Blocked
- đĨ Critical (stands out from warning!)
- â ī¸ Warning
- â Success
- âī¸ Completed
- âšī¸ Info
- đ Trace
ANSI Colors (Feature Flag)
Enable with features = ["ansi-colors"]:
use Severity;
let severity = Error;
println!;
// Output: Error in bold red
// Combine with emojis for maximum clarity
println!;
// Output: â Critical failure (in red)
Serialization
Enable with features = ["serde"]:
use *;
use serde_json;
let codes = vec!;
// Serialize to JSON
let json = to_string?;
// [{"severity":"Error","component":"CRYPTO","primary":"SALT","sequence":1}, ...]
// Severities support full round-trip
let severity = Error;
let json = to_string?;
let restored: Severity = from_str?;
Sequence Conventions
The Waddling ecosystem uses semantic sequence numbers for common patterns:
| Sequence | Meaning | Example |
|---|---|---|
| 001 | MISSING | Required item not provided |
| 002 | MISMATCH | Values don't match expected type |
| 003 | INVALID | Format/validation failed |
| 021 | NOTFOUND | Resource not found |
| 025 | CORRUPTED | Data corruption detected |
| 031-897 | (project) | Domain-specific sequences |
| 999 | COMPLETE | Full completion |
Benefits: .001 always means "missing" across ALL Waddling projects.
See docs/SEQUENCE-CONVENTIONS.md for the complete list.
Examples
Run the examples to see features in action:
# Basic emoji support
# ANSI colored terminal output
# Serde serialization
# Complete severity matrix
Documentation
- CHANGELOG.md - Version history and release notes
- docs/FEATURE_FLAGS.md - Comprehensive feature guide
- API Documentation - Full API reference on docs.rs
License
Dual-licensed under MIT or Apache-2.0.