Below is a diff of a small Rust module that prepares a short description of a string package and saves it to a file. After the changes, observable problems appeared in error handling.
What the contract requires:
summarize_batch takes a list of package strings and returns a string of the form batch=<N>;last=<VALUE>.trim().<VALUE> is the last matching string in the original order; if there are none, - is used.store_batch first validates and builds the summary, then writes it to the target file.StoreState.saved_batches counter increases only after a successful file write.You need to find and describe exactly two independent defects in the modified version.
Reproduction steps:
store_batch with a path like missing/out.txt, where the missing directory does not exist.summarize_batch on input vec![" first ".into(), " ".into(), "second".into()].Assumptions:
fs::write call.Rust 1.85.0, edition 2021; std only; execution mode is a normal unit-level function call without async and without external services.
Use line comments to explain the problem, its impact, the fix and how to test it.