5 releases
Uses new Rust 2024
new 0.1.5 | May 15, 2025 |
---|---|
0.1.4 | May 14, 2025 |
0.1.3 | Apr 21, 2025 |
0.1.2 | Apr 20, 2025 |
0.1.1 | Apr 20, 2025 |
#1191 in Rust patterns
418 downloads per month
9KB
cdumay_error_base64
A small utility crate for converting base64::DecodeError
into structured, typed errors using the cdumay_error
framework. This allows consistent, meaningful error reporting with custom codes, messages, and additional context.
Features
- Maps all variants of
base64::DecodeError
into structuredcdumay_error::Error
types. - Provides unique error codes, HTTP status codes, and human-readable messages.
- Easily attach contextual metadata for better debugging.
- Simple integration into any Rust project using
base64
andcdumay_error
. - Provides a convenient
convert_result!
macro for error conversion
Usage
Using the Base64DecodeErrorConverter
directly:
use base64::{engine::general_purpose, Engine as _};
use cdumay_error::ErrorConverter;
use std::collections::BTreeMap;
use cdumay_error_base64::Base64DecodeErrorConverter;
fn decode_base64(input: &str) -> Result<Vec<u8>, cdumay_error::Error> {
general_purpose::STANDARD.decode(input).map_err(|e| {
let mut context = BTreeMap::new();
context.insert("input".to_string(), serde_value::Value::String(input.to_string()));
Base64DecodeErrorConverter::convert(&e, "Failed to decode base64".to_string(), context)
})
}
Using the convert_result!
macro:
use base64::{engine::general_purpose, Engine as _};
use cdumay_error::ErrorConverter;
use std::collections::BTreeMap;
use cdumay_error_base64::convert_result;
fn decode_base64(input: &str) -> Result<Vec<u8>, cdumay_error::Error> {
convert_result!(general_purpose::STANDARD.decode(input), "Failed to decode base64")
}
Dependencies
~0.7–1.4MB
~30K SLoC