Skip to main content

Crate charon_error

Crate charon_error 

Source
Expand description

§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 ErrorReport to preserve full context
  • Sensitivity labels: Tag data as Public, Private, Internal, or Confidential to control what gets shared
  • Panic hooks: Capture panics and display human-readable reports with setup_panic! and setup_panic_simple!
  • Issue submission: Generate pre-filled GitLab issue URLs from errors via GitLabErrorReport
  • Tracing integration: Works with the tracing crate - use #[instrument] and tracing::error!() alongside ErrorReport
  • Flexible formatting: Configure output detail with ErrorFmtSettings

§Quick Start

use charon_error::prelude::*;

#[derive(Debug, ThisError)]
enum AppError {
    #[error("failed to load config")]
    ConfigLoad,
}

fn load_config() -> ResultER<String> {
    std::fs::read_to_string("config.toml")
        .change_context(AppError::ConfigLoad)?;
    Ok("loaded".to_owned())
}

§Using ResultER<T>

ResultER<T> is a type alias for Result<T, ErrorReport>. Use it as your return type and the ResultExt trait methods become available on any Result or Option:

use charon_error::prelude::*;

fn example() -> ResultER<()> {
    let value: i32 = "not_a_number"
        .parse::<i32>()
        .change_context(StringError::new("parsing failed"))?;
    Ok(())
}

Modules§

prelude
Prelude module for convenient imports.

Macros§

format_string
Create an ErrorFormatObj::FormatString from multiple values.
map
Create an IndexMap with string keys from key-value pairs.
setup_panic
Set up a custom panic hook with issue submission and known-error matching.
setup_panic_simple
Set up a simple panic hook that prints a human-readable error message.

Structs§

ErrorFmtSettings
Configuration for error formatting output.
ErrorFrame
A single frame in an error chain, capturing one error with its full context.
ErrorReport
The core error type that collects a chain of ErrorFrames.
GitLabERGlobalSettings
Global configuration for GitLab issue submission.
GitLabErrorReport
GitLab implementation of SubmitErrorReport.
SourceLocation
Captures a source code location (file, line, column).
StringError
A simple error type that wraps a string message.

Enums§

ErrorAttachment
Data that can be attached to an ErrorFrame for additional diagnostics.
ErrorFmtLoD
Level of detail for error formatting output.
ErrorFormatObj
An intermediate representation for structured error output.
ErrorSensitivityLabel
Controls the visibility and handling of data based on its sensitivity.
FilterObjectError
Error returned when filtering object fields with a key that does not exist.
IndentationStyle
Indentation style for formatted output.
LinkDebugIde
Format for source location links in terminal output.

Traits§

ErrorFmt
Trait for converting error types into a structured ErrorFormatObj tree.
ResultExt
Extension trait for Result and Option that integrates with ErrorReport.
SubmitErrorReport
Trait for converting an ErrorReport into a submittable issue report.

Type Aliases§

ResultER
Convenience type alias for Result<T, ErrorReport>.