Crates.io | cdumay_error_base64 |
lib.rs | cdumay_error_base64 |
version | 0.1.8 |
created_at | 2025-04-20 21:16:35.89082+00 |
updated_at | 2025-05-26 13:04:42.742336+00 |
description | A Rust Library for base64 error |
homepage | https://github.com/cdumay/cdumay_error_base64 |
repository | https://github.com/cdumay/cdumay_error_base64 |
max_upload_size | |
id | 1642022 |
size | 18,213 |
A small utility crate for converting base64::DecodeError
into structured, typed errors using the cdumay_core
framework. This allows consistent, meaningful error reporting with custom codes, messages, and additional context.
base64::DecodeError
into structured cdumay_core::Error
types.base64
and cdumay_core
.convert_result!
macro for error conversionUsing the Base64DecodeErrorConverter
directly:
use base64::{engine::general_purpose, Engine as _};
use std::collections::BTreeMap;
use cdumay_core::{ErrorConverter, Error};
use cdumay_error_base64::Base64DecodeErrorConverter;
fn decode_base64(input: &str) -> cdumay_core::Result<Vec<u8>> {
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_core::{ErrorConverter, Error};
use std::collections::BTreeMap;
use cdumay_error_base64::convert_result;
fn decode_base64(input: &str) -> cdumay_core::Result<Vec<u8>> {
let mut context = BTreeMap::new();
context.insert("input".to_string(), serde_value::Value::String(input.to_string()));
convert_result!(general_purpose::STANDARD.decode(input), context, "Failed to decode base64")
}