Skip to content

Commit

Permalink
Fix multiline error report to log file
Browse files Browse the repository at this point in the history
  • Loading branch information
Riey committed Oct 27, 2022
1 parent b2d18e4 commit 0a45c7e
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions crates/erars-loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 436,12 @@ pub fn run_script(
.unwrap();
}
log::error!("총 {}개의 에러가 발생했습니다.", diagnostic.labels.len());
codespan_reporting::term::emit(&mut LogWriter::default(), &config, &files, &diagnostic).unwrap();
anyhow::bail!("총 {}개의 에러가 발생했습니다.", diagnostic.labels.len());
{
let mut writer = LogWriter::default();
codespan_reporting::term::emit(&mut writer, &config, &files, &diagnostic).unwrap();
std::io::Write::flush(&mut writer).unwrap();
}
anyhow::bail!("Compile error");
}
}

Expand All @@ -452,19 456,14 @@ struct LogWriter(String);
impl std::io::Write for LogWriter {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
let s = std::str::from_utf8(buf).unwrap();
if let Some((l, r)) = s.split_once('\n') {
self.0.push_str(l);
log::error!("{}", self.0);
self.0.clear();
self.0.push_str(r);
} else {
self.0.push_str(s);
}
self.0.push_str(s);
Ok(buf.len())
}

fn flush(&mut self) -> std::io::Result<()> {
log::error!("{}", self.0);
for line in self.0.lines() {
log::error!("{line}");
}
self.0.clear();
Ok(())
}
Expand Down

0 comments on commit 0a45c7e

Please sign in to comment.