aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_flycheck/src/lib.rs55
1 files changed, 17 insertions, 38 deletions
diff --git a/crates/ra_flycheck/src/lib.rs b/crates/ra_flycheck/src/lib.rs
index f099bdfe8..13494a731 100644
--- a/crates/ra_flycheck/src/lib.rs
+++ b/crates/ra_flycheck/src/lib.rs
@@ -4,8 +4,8 @@
4mod conv; 4mod conv;
5 5
6use std::{ 6use std::{
7 env, error, fmt, 7 env,
8 io::{BufRead, BufReader}, 8 io::{self, BufRead, BufReader},
9 path::PathBuf, 9 path::PathBuf,
10 process::{Command, Stdio}, 10 process::{Command, Stdio},
11 time::Instant, 11 time::Instant,
@@ -279,27 +279,12 @@ enum CheckEvent {
279 End, 279 End,
280} 280}
281 281
282#[derive(Debug)]
283pub struct CargoError(String);
284
285impl fmt::Display for CargoError {
286 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
287 write!(f, "Cargo failed: {}", self.0)
288 }
289}
290impl error::Error for CargoError {}
291
292fn run_cargo( 282fn run_cargo(
293 mut command: Command, 283 mut command: Command,
294 on_message: &mut dyn FnMut(cargo_metadata::Message) -> bool, 284 on_message: &mut dyn FnMut(cargo_metadata::Message) -> bool,
295) -> Result<(), CargoError> { 285) -> io::Result<()> {
296 dbg!(&command); 286 let mut child =
297 let mut child = command 287 command.stdout(Stdio::piped()).stderr(Stdio::null()).stdin(Stdio::null()).spawn()?;
298 .stdout(Stdio::piped())
299 .stderr(Stdio::null())
300 .stdin(Stdio::null())
301 .spawn()
302 .expect("couldn't launch cargo");
303 288
304 // We manually read a line at a time, instead of using serde's 289 // We manually read a line at a time, instead of using serde's
305 // stream deserializers, because the deserializer cannot recover 290 // stream deserializers, because the deserializer cannot recover
@@ -313,13 +298,7 @@ fn run_cargo(
313 let mut read_at_least_one_message = false; 298 let mut read_at_least_one_message = false;
314 299
315 for line in stdout.lines() { 300 for line in stdout.lines() {
316 let line = match line { 301 let line = line?;
317 Ok(line) => line,
318 Err(err) => {
319 log::error!("Couldn't read line from cargo: {}", err);
320 continue;
321 }
322 };
323 302
324 let message = serde_json::from_str::<cargo_metadata::Message>(&line); 303 let message = serde_json::from_str::<cargo_metadata::Message>(&line);
325 let message = match message { 304 let message = match message {
@@ -340,20 +319,20 @@ fn run_cargo(
340 // It is okay to ignore the result, as it only errors if the process is already dead 319 // It is okay to ignore the result, as it only errors if the process is already dead
341 let _ = child.kill(); 320 let _ = child.kill();
342 321
343 let err_msg = match child.wait() { 322 let exit_status = child.wait()?;
344 Ok(exit_code) if !exit_code.success() && !read_at_least_one_message => { 323 if !exit_status.success() && !read_at_least_one_message {
345 // FIXME: Read the stderr to display the reason, see `read2()` reference in PR comment: 324 // FIXME: Read the stderr to display the reason, see `read2()` reference in PR comment:
346 // https://github.com/rust-analyzer/rust-analyzer/pull/3632#discussion_r395605298 325 // https://github.com/rust-analyzer/rust-analyzer/pull/3632#discussion_r395605298
326 return Err(io::Error::new(
327 io::ErrorKind::Other,
347 format!( 328 format!(
348 "the command produced no valid metadata (exit code: {:?}): {:?}", 329 "the command produced no valid metadata (exit code: {:?}): {:?}",
349 exit_code, command 330 exit_status, command
350 ) 331 ),
351 } 332 ));
352 Err(err) => format!("io error: {:?}", err), 333 }
353 Ok(_) => return Ok(()),
354 };
355 334
356 Err(CargoError(err_msg)) 335 Ok(())
357} 336}
358 337
359fn cargo_binary() -> String { 338fn cargo_binary() -> String {