Skip to content

Commit 95c0fb6

Browse files
Wilfredmeta-codesync[bot]
authored andcommitted
Report write errors in glean-encode-scip2 instead of swallowing them
Summary: `GleanJSONOutput::write` takes its writer by value and never flushes it, so the `BufWriter` created in `build_json` is drained only by `Drop`, which discards the error. A failing final write is therefore invisible and the tool exits 0 after logging `Wrote 1 file (N GiB)`. `std::fs::metadata(...).unwrap_or(0)` hid a failing `stat` the same way. Add an explicit `w.flush()?`, and propagate the `metadata` error. Reviewed By: echistyakov Differential Revision: D115445577 fbshipit-source-id: 2aefac56591c9c6e5ff3084b9123d22611c0c85b
1 parent 857211c commit 95c0fb6

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

glean/lang/scip/indexer/scip_to_glean/cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ fn build_json(args: BuildJsonArgs) -> Result<()> {
261261
let writer = std::io::BufWriter::new(write);
262262

263263
shard.write(writer)?;
264-
total_bytes += std::fs::metadata(&file).map(|m| m.len()).unwrap_or(0);
264+
total_bytes += std::fs::metadata(&file)?.len();
265265
}
266266
info!(
267267
"Wrote {} {} ({})",

glean/lang/scip/indexer/scip_to_glean/cli/src/output.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,10 @@ impl GleanJSONOutput {
543543
)?;
544544
w.write_all(b"]\n")?;
545545

546+
// A buffered writer would otherwise flush on drop, which discards the
547+
// error, so a failed final write would look like success.
548+
w.flush()?;
549+
546550
Ok(())
547551
}
548552
}

0 commit comments

Comments
 (0)