charon-error
Structured error handling for Rust with rich error reports, data sensitivity labels, panic capture, and GitLab issue integration.
Named after Charon, the Greek ferryman of the dead across the river Styx. This crate ferries your program from a running state to a graceful death, collecting every detail along the way.
Features
- Error chains — Stack multiple errors with
ErrorReportto preserve full context from root cause to top-level failure - Sensitivity labels — Tag data as
Public,Private,Internal, orConfidentialto control what information gets shared in reports - Panic hooks — Capture panics and display human-readable error messages with
setup_panic!andsetup_panic_simple! - Issue submission — Generate pre-filled GitLab issue URLs directly from errors so users can report bugs with one click
- Tracing integration — Works with the
tracingcrate. Use#[instrument]and span traces are captured automatically in error frames - Flexible formatting — Configure output detail level (Compact, Medium, Full, Debug) and indentation style
Installation
Add to your Cargo.toml:
[]
= "0.1"
Quick Start
use *;
ResultER<T> is a type alias for Result<T, ErrorReport>. The ResultExt trait (imported via the prelude) adds .change_context(), .error_attach(), and .unwrap_error() to any Result or Option.
Error Context and Attachments
Adding Context
Use .change_context() to wrap errors with higher-level meaning:
use *;
Attaching Data
Attach diagnostic data to errors with sensitivity labels:
use *;
Sensitivity Labels
ErrorSensitivityLabel controls who can see attached data:
| Level | Data Owner | Other Users | Internal | Encrypted |
|---|---|---|---|---|
Public |
yes | yes | yes | no |
Private |
yes | no | yes | no |
PrivateConfidential |
yes | no | no | yes |
Internal |
no | no | yes | no |
Confidential |
no | no | yes | yes |
HighlyConfidential |
no | no | yes | yes |
Note: Encryption is not implemented yet.
Panic Hooks
Full Panic Hook with Issue Submission
use *;
use *;
When a panic occurs:
- Known errors: Displays a friendly message from
check_if_common_errors - Unknown errors (debug build): Shows the full error report with a clickable link to create a GitLab issue
- Unknown errors (release build): Shows a user-friendly message with report instructions
Simple Panic Hook
For applications that do not need issue submission:
use *;
Tracing Integration
charon-error integrates with the tracing crate. Annotate functions with #[instrument] and span traces are automatically captured in each error frame:
use *;
The error report will include the span trace showing the call chain through process_request and validate_user.
Error Formatting
Control output detail with ErrorFmtSettings:
use ;
let report = from_error;
// Compact output
let compact = report.stringify;
// Full output with no color (for logs)
let full = report.stringify;
Detail levels:
- Compact — Key fields only
- Medium — Balanced (default)
- SubmitReport — Tailored for issue submission (no color)
- Full — All available information
- Debug — Structural output for debugging the error system itself
GitLab Configuration
GitLabERGlobalSettings fields:
| Field | Default | Description |
|---|---|---|
domain |
"gitlab.com" |
GitLab instance domain |
project_path |
"<not set>" |
Group/project path (e.g. "org/project") |
labels |
["Auto Generated Issue"] |
Labels applied to created issues |
url_char_limit |
2085 |
Max URL length before trimming report |
title_char_limit |
1024 |
Max issue title length |
description_char_limit |
1_048_576 |
Max issue description length (1MB) |
Roadmap
- GitHub issue submission support
- Encryption for
ConfidentialandHighlyConfidentialdata - Configurable global formatting settings
Use of AI in this project
This project was hand written before AI. It will be using AI to assist in development. However ALL code is manually reviewed and improve.
License
The code in this project is licensed under the MIT or Apache 2.0 license.
All contributions, code and documentation, to this project will be similarly licensed.