Module diagnostics
Expand description
See diagnostics for the system contract and examples.
Bounded local engine diagnostics with severity filtering and consecutive dedup.
Codes are 1..=64 bytes, messages <=1024 bytes; no transport or logging backend.
Capacity counts records. Repeated equal records retain first/last host tick.
Attach source coordinates, an operation and a suggested fix with
Diagnostics::record_with_context. Context is copied only when a new record
is retained and participates in deduplication. All text limits count UTF-8
bytes, and caller-provided diagnostic codes are preserved verbatim.
use ferravex_engine::diagnostics::{
DiagnosticContext, DiagnosticSource, Diagnostics, Severity,
};
let mut diagnostics = Diagnostics::new(32, Severity::Warning);
diagnostics.record_with_context(12, Severity::Error, "scene.invalid_mass",
"mass must be positive", DiagnosticContext {
source: Some(DiagnosticSource { file: "levels/arena.scene", line: 8, column: 5 }),
operation: Some("load_scene"),
help: Some("Set mass to a finite number greater than zero."),
})?;
let json = diagnostics.to_json();
assert!(json.starts_with("{\"schema_version\":1,"));
// Formatting streams the same JSON without an intermediate String.
assert_eq!(format!("{}", diagnostics.json()), json);Diagnostics::write_ndjson exports individual records followed by a counter
summary, with one versioned JSON object per line. Diagnostics::summary
provides the same counts without formatting or allocating. These additions
leave the existing version 1 JSON snapshot unchanged.
Structs§
- Diagnostic
- Diagnostic
Context - Optional bounded context.
NoneandSome("")remain distinct in the export. Borrowed strings are copied into the collector only for a new retained record. - Diagnostic
Counts - Retained record and occurrence counts, returned by
Diagnostics::summary. See that method’s example for total and per-severity queries. - Diagnostic
Source - Source coordinates supplied by the producer; both line and column are 1-based. Columns count Unicode scalar values, not UTF-8 bytes or display cells.
- Diagnostic
Summary - Fixed-size snapshot of collector configuration and counters.
Constructed without allocation by
Diagnostics::summary. Counts describe retained records, not a lifetime event total; filtered/rejected input is absent. - Diagnostics
- Diagnostics
Json - Display adapter created by
Diagnostics::json. No intermediate allocation. - Diagnostics
Ndjson - Display adapter created by
Diagnostics::ndjson. See that method’s example for streaming to an I/O writer without an intermediate allocation.
Enums§
- Diagnostic
Error - Diagnostic
Input Error - Detailed validation failure returned by
Diagnostics::record_with_context. Rejected input never changes retained records or eviction counters. - Severity