Resolves the 142 findings from tidal/docs/reviews/CODE_REVIEW_m0-m10.md across the engine, server, net, and CLI surfaces: - WAL/session-journal durability, checkpoint format, and crash-recovery hardening - Replication shipper/receiver, tenant isolation, and migration paths - Cluster scatter-gather, router, standalone server + health/offload endpoints - tidalctl refactored into command modules with JSON output and WAL-state tooling - Cohort, governance, signal-ledger, and vector-registry correctness fixes - Expanded UAT/integration/durability test coverage across all milestones
28 lines
991 B
Rust
28 lines
991 B
Rust
//! Shared JSON serialization helper.
|
|
//!
|
|
//! All `tidalctl` JSON flows through this single `serde_json`-backed path, so
|
|
//! control characters, unicode, and quotes in any string field (paths, error
|
|
//! messages, reasons) are always escaped correctly — there is no hand-rolled
|
|
//! escaping left to get wrong.
|
|
|
|
use serde::Serialize;
|
|
|
|
use crate::CliError;
|
|
|
|
/// Serialize a value to JSON, compact or pretty.
|
|
///
|
|
/// # Errors
|
|
///
|
|
/// Returns [`CliError`] if serialization fails. Serialization of these plain
|
|
/// data structs is infallible in practice (no maps with non-string keys, no
|
|
/// custom `Serialize` that can error), so this is a defensive boundary rather
|
|
/// than an expected path.
|
|
pub(crate) fn render_json<T: Serialize>(value: &T, pretty: bool) -> Result<String, CliError> {
|
|
let result = if pretty {
|
|
serde_json::to_string_pretty(value)
|
|
} else {
|
|
serde_json::to_string(value)
|
|
};
|
|
result.map_err(|e| CliError::new(format!("internal json error: {e}")))
|
|
}
|