Stream native failure manifests during publication

This commit is contained in:
gloamxun committed 2026-11-19 14:50:11 +08:00
1 parent 72ed779749
commit 5aa7dc7331
5 files changed
+46 -9

No files matched your search

+14 -6
View File
@@ -403,12 +403,20 @@ impl CompileFailure {
schema: u32,
failure: &'a CompileFailure,
}
let bytes = serde_json::to_vec_pretty(&Report {
schema: 1,
failure: self,
})
.map_err(|e| e.to_string())?;
PreparedOutput::write(&destination, &bytes)?.commit_new(&destination)
PreparedOutput::write_with(&destination, |file| {
use std::io::{BufWriter, Write};
let mut buffer = BufWriter::new(file);
serde_json::to_writer_pretty(
&mut buffer,
&Report {
schema: 1,
failure: self,
},
)
.map_err(|error| error.to_string())?;
buffer.flush().map_err(|error| error.to_string())
})?
.commit_new(&destination)
}
fn persist_requested(mut self) -> Self {
if let Some(path) = &self.request.failure_manifest {
+11 -1
View File
@@ -1855,8 +1855,18 @@ impl PreparedOutput {
Ok(version)
}
pub fn write(output: &Path, bytes: &[u8]) -> Result<Self, String> {
Self::write_with(output, |file| {
file.write_all(bytes).map_err(|error| error.to_string())
})
}
pub(crate) fn write_with(
output: &Path,
write: impl FnOnce(&mut File) -> Result<(), String>,
) -> Result<Self, String> {
let (prepared, mut file) = Self::create(output)?;
let written = file.write_all(bytes).and_then(|()| file.sync_all());
let written = write(&mut file)
.and_then(|()| file.sync_all().map_err(|error| error.to_string()));
drop(file);
written.map_err(|error| format!("stage output {}: {error}", output.display()))?;
Ok(prepared)