Skip to main content

read_valid_or_quarantine

Function read_valid_or_quarantine 

Source
pub fn read_valid_or_quarantine<T, F>(
    path: &Path,
    parse: F,
) -> Result<Option<T>>
where F: FnOnce(&str) -> Option<T>,
Expand description

Read path and parse it with parse. Missing → Ok(None). If the file exists but is empty / whitespace-only / fails to parse (a corrupt state file — e.g. a 0-byte controller-state.json left by a pre-write_atomic interrupted write or an external truncation), quarantine the bad file by renaming it aside and return Ok(None) so the caller reboots from a clean slate instead of wedging on every future read.

This is the read counterpart to write_atomic (#corrupt-state-quarantine): write_atomic stops new 0-byte files; this recovers automatically from an already-corrupt one, so a partial write no longer manifests as the manual start "timed out waiting for project controller" move-aside dance.