Render Json
Produces a DiagnosticDto JSON payload for use in REST API error
responses and MCP tool results. The DTO is the canonical error shape
for all new endpoints introduced in the block-validation-dashboard feature
— endpoints MUST emit DiagnosticDto rather than the legacy
{"error": "..."} envelope.
Sanitisation and path policy
Two safety transforms are applied during serialisation:
- String fields (
message,hint,yaml_excerpt) are passed throughsuper::sanitize::sanitize_for_serializationso embedded ANSI escapes, BEL/CR, and UnicodeCf(bidi/zero-width) codepoints from a malicious YAML cannot reach a JSON consumer’s rendering surface (web UI, MCP client, log viewer). source_fileis canonicalised to a workspace-relative path. When the path lies under the current working directory it is emitted relative (./blocks/postgres.yml); otherwise only the file name is emitted (postgres.yml). Absolute paths are never serialised — this prevents daemon-host filesystem layout from leaking through API/MCP responses.
Key Types
DiagnosticDto— JSON-serialisable DTO mirroringDiagnostic.SpanDto— JSON form ofsuper::Span.JsonRenderer— implementsDiagnosticRendererfor JSON output.
Example
use stackie::diagnostic::{Diagnostic, DiagnosticCode, DiagnosticRenderer};
use stackie::diagnostic::render_json::JsonRenderer;
use std::sync::Arc;
let diag = Diagnostic::new(
DiagnosticCode::E101EmptyName,
"Block name cannot be empty",
Arc::from("name: \n"),
);
let json = JsonRenderer.render(&diag);
assert!(json.contains("E101"));