Skip to content

Print out the output line that fails json parsing #33392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/tools/compiletest/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use errors::{Error, ErrorKind};
use rustc_serialize::json;
use std::str::FromStr;
use std::path::Path;
use runtest::{fatal_proc_rec, ProcRes};

// These structs are a subset of the ones found in
// `syntax::errors::json`.
Expand Down Expand Up @@ -55,13 +56,13 @@ struct DiagnosticCode {
explanation: Option<String>,
}

pub fn parse_output(file_name: &str, output: &str) -> Vec<Error> {
pub fn parse_output(file_name: &str, output: &str, proc_res: &ProcRes) -> Vec<Error> {
output.lines()
.flat_map(|line| parse_line(file_name, line))
.flat_map(|line| parse_line(file_name, line, output, proc_res))
.collect()
}

fn parse_line(file_name: &str, line: &str) -> Vec<Error> {
fn parse_line(file_name: &str, line: &str, output: &str, proc_res: &ProcRes) -> Vec<Error> {
// The compiler sometimes intermingles non-JSON stuff into the
// output. This hack just skips over such lines. Yuck.
if line.chars().next() == Some('{') {
Expand All @@ -72,7 +73,9 @@ fn parse_line(file_name: &str, line: &str) -> Vec<Error> {
expected_errors
}
Err(error) => {
panic!("failed to decode compiler output as json: `{}`", error);
fatal_proc_rec(None, &format!(
"failed to decode compiler output as json: `{}`\noutput: {}\nline: {}",
error, line, output), proc_res);
}
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ fn check_expected_errors(revision: Option<&str>,
let expect_note = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Note));

// Parse the JSON output from the compiler and extract out the messages.
let actual_errors = json::parse_output(&file_name, &proc_res.stderr);
let actual_errors = json::parse_output(&file_name, &proc_res.stderr, &proc_res);
let mut unexpected = 0;
let mut not_found = 0;
let mut found = vec![false; expected_errors.len()];
Expand Down Expand Up @@ -1111,7 +1111,7 @@ struct ProcArgs {
args: Vec<String>,
}

struct ProcRes {
pub struct ProcRes {
status: Status,
stdout: String,
stderr: String,
Expand Down Expand Up @@ -1576,7 +1576,7 @@ fn fatal(revision: Option<&str>, err: &str) -> ! {
error(revision, err); panic!();
}

fn fatal_proc_rec(revision: Option<&str>, err: &str, proc_res: &ProcRes) -> ! {
pub fn fatal_proc_rec(revision: Option<&str>, err: &str, proc_res: &ProcRes) -> ! {
error(revision, err);
print!("\
status: {}\n\
Expand Down