File tree 2 files changed +78
-8
lines changed
2 files changed +78
-8
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ use std::fmt;
5
5
use std:: path:: Path ;
6
6
use std:: process:: { Command , Output , Stdio } ;
7
7
8
+ use failure:: Fail ;
8
9
use jobserver:: Client ;
9
10
use shell_escape:: escape;
10
11
@@ -271,19 +272,20 @@ impl ProcessBuilder {
271
272
272
273
{
273
274
let to_print = if capture_output { Some ( & output) } else { None } ;
274
- if !output. status . success ( ) {
275
- return Err ( process_error (
276
- & format ! ( "process didn't exit successfully: {}" , self ) ,
277
- Some ( output. status ) ,
278
- to_print,
279
- ) . into ( ) ) ;
280
- } else if let Some ( e) = callback_error {
275
+ if let Some ( e) = callback_error {
281
276
let cx = process_error (
282
277
& format ! ( "failed to parse process output: {}" , self ) ,
283
278
Some ( output. status ) ,
284
279
to_print,
285
280
) ;
286
- return Err ( e. context ( cx) . into ( ) ) ;
281
+ return Err ( cx. context ( e) . into ( ) ) ;
282
+ } else if !output. status . success ( ) {
283
+ return Err ( process_error (
284
+ & format ! ( "process didn't exit successfully: {}" , self ) ,
285
+ Some ( output. status ) ,
286
+ to_print,
287
+ )
288
+ . into ( ) ) ;
287
289
}
288
290
}
289
291
Original file line number Diff line number Diff line change @@ -4435,3 +4435,71 @@ Caused by:
4435
4435
. with_status ( 101 )
4436
4436
. run ( ) ;
4437
4437
}
4438
+
4439
+ #[ test]
4440
+ fn json_parse_fail ( ) {
4441
+ // Ensure when json parsing fails, and rustc exits with non-zero exit
4442
+ // code, that a useful error message is displayed.
4443
+ let foo = project ( )
4444
+ . file (
4445
+ "Cargo.toml" ,
4446
+ r#"
4447
+ [package]
4448
+ name = "foo"
4449
+ version = "0.1.0"
4450
+ [dependencies]
4451
+ pm = { path = "pm" }
4452
+ "# ,
4453
+ )
4454
+ . file (
4455
+ "src/lib.rs" ,
4456
+ r#"
4457
+ #[macro_use]
4458
+ extern crate pm;
4459
+
4460
+ #[derive(Foo)]
4461
+ pub struct S;
4462
+ "# ,
4463
+ )
4464
+ . file (
4465
+ "pm/Cargo.toml" ,
4466
+ r#"
4467
+ [package]
4468
+ name = "pm"
4469
+ version = "0.1.0"
4470
+ [lib]
4471
+ proc-macro = true
4472
+ "# ,
4473
+ )
4474
+ . file (
4475
+ "pm/src/lib.rs" ,
4476
+ r#"
4477
+ extern crate proc_macro;
4478
+ use proc_macro::TokenStream;
4479
+
4480
+ #[proc_macro_derive(Foo)]
4481
+ pub fn derive(_input: TokenStream) -> TokenStream {
4482
+ eprintln!("{{evil proc macro}}");
4483
+ panic!("something went wrong");
4484
+ }
4485
+ "# ,
4486
+ )
4487
+ . build ( ) ;
4488
+
4489
+ foo. cargo ( "build --message-format=json" )
4490
+ . with_stderr (
4491
+ "\
4492
+ [COMPILING] pm [..]
4493
+ [COMPILING] foo [..]
4494
+ [ERROR] Could not compile `foo`.
4495
+
4496
+ Caused by:
4497
+ compiler produced invalid json: `{evil proc macro}`
4498
+
4499
+ Caused by:
4500
+ failed to parse process output: `rustc [..]
4501
+ " ,
4502
+ )
4503
+ . with_status ( 101 )
4504
+ . run ( ) ;
4505
+ }
You can’t perform that action at this time.
0 commit comments