19 releases (10 breaking)

Uses new Rust 2024

0.11.0-rc.3 Apr 3, 2026
0.11.0-rc.1 Mar 29, 2026
0.8.0-rc.2 Dec 6, 2025
0.8.0-rc.1 Nov 10, 2025
0.1.0 Jan 20, 2025

#700 in Text processing


Used in web-scrape

MIT license

22KB
533 lines

clerr

Crates.io Docs.rs License: MIT

This library aids in command-line error reporting.

clerr = "0.11.0-rc.3"

Examples

Note: The output for each example would be colored text. This is not supported in Markdown files.

Simple Report

use clerr::*;

let code: Code = Code::error("E001", "file not found");
let report: Report = Report::from(code);
eprintln!("{}", report);
error[E001]: file not found

Token Info

Highlight a specific token in a source line with a message, similar to rustc output.

use clerr::*;

let code: Code = Code::warning("W012", "unused variable");
let info: TokenInfo = TokenInfo {
    severity: Severity::Warning,
    file_name: "src/main.rs",
    line: 8,
    position: 9,
    line_text: "    let x = 42;",
    token_len: 1,
    message: "consider prefixing with `_`",
};
let report: Report = Report::from(code).with_entry(info);
eprintln!("{}", report);
warning[W012]: unused variable
 --> src/main.rs [line=8, position=9]
  |
8 |     let x = 42;
  |         ^ --- consider prefixing with `_`
  |

Properties

Display aligned key-value pairs under a report.

use clerr::*;

let props: Properties = Properties::default()
    .with_property("file", "/etc/config.yml")
    .with_property("expected", "utf-8")
    .with_property("found", "binary");
let code: Code = Code::error("E042", "invalid encoding");
let report: Report = Report::from(code).with_entry(props);
eprintln!("{}", report);
error[E042]: invalid encoding
    file:      /etc/config.yml
    expected:  utf-8
    found:     binary

Severity Levels

Three severity levels are available, each with a distinct color:

Level Color
Error BrightRed
Warning BrightYellow
Info BrightBlue

These colors are intentionally fixed for consistency and consideration for the colorblind.

Issues & Contributing

See ISSUES.md for issues & future work and CONTRIBUTING.md for guidelines.

Dependencies

~1.5–3MB
~52K SLoC