From f41ae64722ab8e501e2123018d1b0101db32442e Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 23 Mar 2021 11:22:33 +0800 Subject: Ignore proc-macro stdout to prevent IPC crash --- crates/proc_macro_api/src/msg.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'crates/proc_macro_api/src') diff --git a/crates/proc_macro_api/src/msg.rs b/crates/proc_macro_api/src/msg.rs index 970f165ed..21e56cc83 100644 --- a/crates/proc_macro_api/src/msg.rs +++ b/crates/proc_macro_api/src/msg.rs @@ -77,13 +77,24 @@ impl Message for Request {} impl Message for Response {} fn read_json(inp: &mut impl BufRead) -> io::Result> { - let mut buf = String::new(); - inp.read_line(&mut buf)?; - buf.pop(); // Remove trailing '\n' - Ok(match buf.len() { - 0 => None, - _ => Some(buf), - }) + loop { + let mut buf = String::new(); + inp.read_line(&mut buf)?; + buf.pop(); // Remove trailing '\n' + + if buf.is_empty() { + return Ok(None); + } + + // Some ill behaved macro try to use stdout for debugging + // We ignore it here + if !buf.starts_with("{") { + log::error!("proc-macro tried to print : {}", buf); + continue; + } + + return Ok(Some(buf)); + } } fn write_json(out: &mut impl Write, msg: &str) -> io::Result<()> { -- cgit v1.2.3