diagprint
Pretty, structured diagnostics and reports for Rust applications.
diagprint turns application failures into structured diagnostics that can be
rendered for terminals, files, JSON, Markdown, or plain text.
v0.4 adds Diagnostic Intelligence: structured suggestions, documentation links, guarded text edits, dry-run validation, interactive fixes, and documentation that can be viewed directly in the terminal with syntax highlighting.
Highlights
- Rich boxed terminal diagnostics
- Unicode-aware display widths
- Automatic terminal sizing
- Source snippets with highlighted ranges
- Intelligent source clipping around the actual error
- Hierarchical error chains
- Notes and help text
- JSON, Markdown, plain-text, and terminal renderers
- UUIDv7 session and report identifiers
- File rotation and retention
- Optional gzip and Zstandard compression
- Custom terminal themes
- Optional Cybercore theme integration
- Structured diagnostic suggestions
- Documentation links
- Machine-applicable text edits
- Stale-edit protection
- UTF-8 boundary validation
- Overlapping-edit rejection
- Dry-run fix validation
- Optional backups
- Interactive fix workflow
- Optional terminal documentation viewer
- Syntax-highlighted documentation examples
- Remote terminal-control sanitization
- Remote document size limits
Installation
Until the crate is published to a registry, use the GitHub repository.
[]
= {
git = "https://github.com/darkstardevx/diagprint.git",
= "v0.4.0"
}
Enable optional features as needed:
[]
= {
git = "https://github.com/darkstardevx/diagprint.git",
= "v0.4.0",
= ["compression", "terminal-docs"]
}
Cybercore integration is available separately:
[]
= {
git = "https://github.com/darkstardevx/diagprint.git",
= "v0.4.0",
= ["cybercore"]
}
Quick Start
use ;
Source Diagnostics
Diagnostics can point directly at source locations.
let diagnostic = reporter
.error
.code
.label;
The terminal renderer follows the highlighted range rather than blindly truncating long source lines from the beginning.
Error Chains
diagprint supports hierarchical causes:
let diagnostic = reporter
.error
.cause
.cause;
Existing std::error::Error chains can also be captured:
let diagnostic = reporter
.error
.from_error;
Diagnostic Intelligence
v0.4 introduces structured suggestions.
use ;
let original =
r#"chrono = { version = "0.4", features = ["clock"] }"#;
let replacement =
r#"chrono = { version = "0.4", features = ["clock", "serde"] }"#;
let diagnostic = reporter
.error
.code
.suggestion;
Terminal output includes the proposed change:
SUGGESTION
TITLE Enable chrono's serde feature
WHY chrono only provides serde implementations when its `serde`
feature is enabled
PATCH Cargo.toml
- chrono = { version = "0.4", features = ["clock"] }
+ chrono = { version = "0.4", features = ["clock", "serde"] }
DOCS chrono documentation
https://docs.rs/chrono/latest/chrono/
APPLY machine-applicable
FIX automatic fix available
Applicability
Every suggestion has an applicability level:
Only MachineApplicable suggestions containing structured edits are eligible
for automatic application.
The classification alone is not enough. diagprint validates the current
filesystem again before writing.
Validate Without Changing Files
Use Fixer::check() as a dry-run:
use Fixer;
let fixer = new;
let check = fixer.check?;
println!;
for file in check.affected_files
No files are modified.
Apply Fixes
let report = new
.backups
.apply?;
println!;
Before changing a file, diagprint verifies:
- the edit is machine-applicable;
- the byte range is valid;
- edit offsets are UTF-8 boundaries;
- edits do not overlap;
- the current file still contains the exact expected text.
If the source changed after the diagnostic was generated, the edit is rejected instead of guessing.
Interactive Fixes
new
.backups
.apply_interactive?;
The terminal workflow exposes only actions that are actually available:
FIX Enable chrono's serde feature
APPLICABILITY machine-applicable
VERIFY current file contents match the proposed edit
[A]pply [S]kip [D]ocs [Q]uit >
If validation fails, [A]pply disappears:
VERIFY blocked: refusing stale edit in Cargo.toml ...
[S]kip [D]ocs [Q]uit >
Suggested Commands
Suggestions may include follow-up commands:
use SuggestedCommand;
let suggestion = new
.command;
Commands are never executed automatically.
They are advisory information only.
Documentation Links
Documentation links are structured data:
let rust = rust_error;
let cargo = cargo_book;
let chrono = docs_rs;
Custom links are also supported:
let link = new;
Terminal Documentation
Enable:
= {
git = "https://github.com/darkstardevx/diagprint.git",
= "v0.4.0",
= ["terminal-docs"]
}
Then:
use ;
let link = rust_error;
new
.width
.open_and_print?;
The viewer:
- accepts HTTP and HTTPS documentation URLs;
- retrieves the document synchronously;
- limits remote document size;
- sanitizes terminal control characters;
- converts HTML to readable terminal text;
- extracts code examples;
- syntax-highlights code with 24-bit ANSI output.
The default maximum remote document size is 2 MiB.
Because the current viewer uses a blocking HTTP client, applications already inside an async runtime should call it from an appropriate blocking worker.
Demo
Or:
Intelligence Demo
Preview:
Validate without writing:
Apply:
Interactive mode with terminal docs:
The demo operates on:
target/diagprint-demo/Cargo.toml
rather than your project's real manifest.
Themes
Terminal presentation is controlled by:
use ;
Create a custom theme:
let theme = Theme ;
Styles support:
- standard ANSI foregrounds;
- ANSI-256 foregrounds and backgrounds;
- 24-bit RGB foregrounds and backgrounds;
- hex colors;
- bold;
- dim;
- italic;
- underline.
color(false) remains authoritative and disables ANSI styling regardless of
the selected theme.
Cybercore Integration
Enable:
= {
git = "https://github.com/darkstardevx/diagprint.git",
= "v0.4.0",
= ["cybercore"]
}
Use the active Cybercore theme:
use Theme;
let theme = cybercore;
Or select a named theme:
let theme = cybercore_or_default;
Useful helpers:
cybercore_theme_names;
cybercore_active_theme_name;
cybercore_theme_exists;
cybercore_named;
diagprint consumes Cybercore's semantic palette rather than duplicating its
hex values.
Showcase
List Cybercore themes:
Choose one:
Output Formats
The same diagnostic data can be rendered as:
- terminal output;
- plain text;
- JSON;
- Markdown.
This keeps diagnostic construction independent from presentation.
Rotation
File reports support:
- size-based rotation;
- hourly rotation;
- daily rotation;
- retention cleanup.
use ;
let policy = RotationPolicy ;
Compression
Enable:
= ["compression"]
Supported formats:
use Compression;
// Compression::Gzip
// Compression::Zstd
Feature Flags
| Feature | Purpose |
|---|---|
compression |
gzip and Zstandard report compression |
cybercore |
Cybercore theme-schema integration |
terminal-docs |
documentation retrieval and terminal syntax highlighting |
All optional features are disabled by default.
Safety Model
diagprint intentionally separates presentation from mutation.
Rendering a diagnostic does not modify files.
Fixer only applies structured text edits that:
- are marked
MachineApplicable; - still match the expected source content;
- use valid UTF-8 boundaries;
- do not overlap.
Suggested shell commands are never automatically executed.
Terminal documentation also sanitizes remote control characters before display and limits the amount of remote content accepted.
Development
Default feature gate:
Full feature gate:
Examples:
Project Status
v0.4.0 — Diagnostic Intelligence
v0.4 expands diagprint from a diagnostic presentation engine into a
structured diagnostic assistance system.
The guiding rule remains:
A diagnostic may explain and propose. Mutation must be explicit, structured, validated, and reject uncertainty.
Roadmap
Potential future work includes:
anyhowintegration;- expanded
thiserrorintegration; tracingintegration;- asynchronous/nonblocking report output;
- async terminal documentation retrieval;
- richer unified diff rendering;
- additional renderers;
- additional structured fix sources.
Registry Publication
Registry publication is intentionally disabled in v0.4 release preparation while the optional Cybercore dependency is sourced from GitHub.
GitHub releases remain fully supported.
Once Cybercore is available from the target registry, the publishing guard can be removed and the registry package verified independently.
Repository
https://github.com/darkstardevx/diagprint
License
Licensed under either of:
- Apache License, Version 2.0
- MIT License
at your option.