fix(manifest): do not panic on corrupt manual_sources.json (#48) #53
No reviewers
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_router!53
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "development_fix_manifest_panic"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Corrupt or malformed
manual_sources.jsonno longer crasheshero_router. The startup path,hero_router list, andhero_router scanall now log a structuredWARNand proceed with an empty in-memory manifest; the next write overwrites the bad file.The mutating CLI commands (
hero_router add/remove) keep their?-propagating behavior — they still fail loudly on a bad file, as a user running them should see the parse error rather than silently lose their sources.Closes #48.
Changes
crates/hero_router/src/manifest.rsManifest::empty(path: PathBuf) -> Selfconstructor — in-memory empty manifest bound topath, no disk I/O.#[derive(Debug)]onManifest(required by the new test'sunwrap_err()).empty_then_save_writes_valid_file_at_given_path— roundtrip throughadd+save+load.load_fails_on_malformed_json— documents the failure mode.crates/hero_router/src/main.rsload_manifest_or_empty(path: &Path) -> Manifestat module scope. Logs viatracing::warn!with structuredpathanderrorfields, then returnsManifest::empty(path.to_path_buf()).unwrap_or_else(|_| panic!(...))blocks:build_and_start(was a/dev/nullfallback that itself panicked)cmd_list(was aload_default()fallback pointing at the same file)cmd_scan(same pattern ascmd_list)crates/hero_router/src/server/rpc.rs,crates/hero_router/src/server/terminal.rsWhy not
/dev/nullas the fallback?The original code's intended safe fallback doesn't work:
/dev/nullexists on Linux, soManifest::loadpassespath.exists(), reads"", andserde_json::from_str("")fails — the fallback itself panics, so the outerunwrap_or_elsedoes too.Manifest::loadwere taught to treat empty asVec::new(), the resultingManifest.pathwould be/dev/null, so every subsequentsave()would silently discard user data (adds from the UI would appear to succeed but persist nothing)./dev/nulldoesn't exist on Windows.Manifest::empty(path)keeps the correct persistence target, so the next write self-heals the bad file.Test Results
cargo test --workspace— 73 passed / 0 failed / 0 ignored (2 new tests inmanifest::tests).cargo clippy --workspace --all-targets -- -D warnings— clean.cargo fmt --all --check— clean.End-to-end verification against the issue repro