Skip to content
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

Show better error message for Windows abnormal termination. #7535

Merged
merged 1 commit into from
Oct 24, 2019
Merged
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
22 changes: 13 additions & 9 deletions src/bin/cargo/commands/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use cargo::ops::{self, CompileFilter, FilterRule, LibRule};

use crate::command_prelude::*;
use cargo::ops::{self, CompileFilter, FilterRule, LibRule};
use cargo::util::errors;
use failure::Fail;

pub fn cli() -> App {
subcommand("test")
Expand Down Expand Up @@ -164,12 +165,15 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let err = ops::run_tests(&ws, &ops, &test_args)?;
match err {
None => Ok(()),
Some(err) => Err(match err.exit.as_ref().and_then(|e| e.code()) {
Some(i) => CliError::new(
failure::format_err!("{}", err.hint(&ws, &ops.compile_opts)),
i,
),
None => CliError::new(err.into(), 101),
}),
Some(err) => {
let context = failure::format_err!("{}", err.hint(&ws, &ops.compile_opts));
let e = match err.exit.as_ref().and_then(|e| e.code()) {
// Don't show "process didn't exit successfully" for simple errors.
Some(i) if errors::is_simple_exit_code(i) => CliError::new(context, i),
Some(i) => CliError::new(err.context(context).into(), i),
None => CliError::new(err.context(context).into(), 101),
};
Err(e)
}
}
}
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use crate::core::manifest::TargetSourcePath;
use crate::core::profiles::{Lto, PanicStrategy, Profile};
use crate::core::Feature;
use crate::core::{PackageId, Target};
use crate::util::errors::{CargoResult, CargoResultExt, Internal, ProcessError};
use crate::util::errors::{self, CargoResult, CargoResultExt, Internal, ProcessError};
use crate::util::machine_message::Message;
use crate::util::paths;
use crate::util::{self, machine_message, ProcessBuilder};
Expand Down Expand Up @@ -271,7 +271,7 @@ fn rustc<'a, 'cfg>(
.as_ref()
.and_then(|perr| perr.exit.and_then(|e| e.code()))
{
Some(n) if n < 128 => Internal::new(err).into(),
Some(n) if errors::is_simple_exit_code(n) => Internal::new(err).into(),
_ => err,
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/cargo/util/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,17 @@ pub fn process_error(
}
}

pub fn is_simple_exit_code(code: i32) -> bool {
// Typical unix exit codes are 0 to 127.
// Windows doesn't have anything "typical", and is a
// 32-bit number (which appears signed here, but is really
// unsigned). However, most of the interesting NTSTATUS
// codes are very large. This is just a rough
// approximation of which codes are "normal" and which
// ones are abnormal termination.
code >= 0 && code <= 127
}

pub fn internal<S: fmt::Display>(error: S) -> failure::Error {
_internal(&error)
}
Expand Down