mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Show full error context on cargo run
error.
This commit is contained in:
parent
4de00d2c7f
commit
18bc90cd0e
@ -1,5 +1,5 @@
|
|||||||
use crate::command_prelude::*;
|
use crate::command_prelude::*;
|
||||||
|
use crate::util::ProcessError;
|
||||||
use cargo::core::Verbosity;
|
use cargo::core::Verbosity;
|
||||||
use cargo::ops::{self, CompileFilter};
|
use cargo::ops::{self, CompileFilter};
|
||||||
|
|
||||||
@ -68,14 +68,18 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match ops::run(&ws, &compile_opts, &values_os(args, "args"))? {
|
|
||||||
None => Ok(()),
|
ops::run(&ws, &compile_opts, &values_os(args, "args")).map_err(|err| {
|
||||||
Some(err) => {
|
let proc_err = match err.downcast_ref::<ProcessError>() {
|
||||||
|
Some(e) => e,
|
||||||
|
None => return CliError::new(err.into(), 101),
|
||||||
|
};
|
||||||
|
|
||||||
// If we never actually spawned the process then that sounds pretty
|
// If we never actually spawned the process then that sounds pretty
|
||||||
// bad and we always want to forward that up.
|
// bad and we always want to forward that up.
|
||||||
let exit = match err.exit {
|
let exit = match proc_err.exit {
|
||||||
Some(exit) => exit,
|
Some(exit) => exit,
|
||||||
None => return Err(CliError::new(err.into(), 101)),
|
None => return CliError::new(err.into(), 101),
|
||||||
};
|
};
|
||||||
|
|
||||||
// If `-q` was passed then we suppress extra error information about
|
// If `-q` was passed then we suppress extra error information about
|
||||||
@ -83,11 +87,10 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
|
|||||||
// information about why it failed so we don't do so as well
|
// information about why it failed so we don't do so as well
|
||||||
let exit_code = exit.code().unwrap_or(101);
|
let exit_code = exit.code().unwrap_or(101);
|
||||||
let is_quiet = config.shell().verbosity() == Verbosity::Quiet;
|
let is_quiet = config.shell().verbosity() == Verbosity::Quiet;
|
||||||
Err(if is_quiet {
|
if is_quiet {
|
||||||
CliError::code(exit_code)
|
CliError::code(exit_code)
|
||||||
} else {
|
} else {
|
||||||
CliError::new(err.into(), exit_code)
|
CliError::new(err.into(), exit_code)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,13 @@ use std::path::Path;
|
|||||||
|
|
||||||
use crate::core::{TargetKind, Workspace};
|
use crate::core::{TargetKind, Workspace};
|
||||||
use crate::ops;
|
use crate::ops;
|
||||||
use crate::util::{CargoResult, ProcessError};
|
use crate::util::CargoResult;
|
||||||
|
|
||||||
pub fn run(
|
pub fn run(
|
||||||
ws: &Workspace<'_>,
|
ws: &Workspace<'_>,
|
||||||
options: &ops::CompileOptions,
|
options: &ops::CompileOptions,
|
||||||
args: &[OsString],
|
args: &[OsString],
|
||||||
) -> CargoResult<Option<ProcessError>> {
|
) -> CargoResult<()> {
|
||||||
let config = ws.config();
|
let config = ws.config();
|
||||||
|
|
||||||
// We compute the `bins` here *just for diagnosis*. The actual set of
|
// We compute the `bins` here *just for diagnosis*. The actual set of
|
||||||
@ -87,13 +87,5 @@ pub fn run(
|
|||||||
|
|
||||||
config.shell().status("Running", process.to_string())?;
|
config.shell().status("Running", process.to_string())?;
|
||||||
|
|
||||||
let result = process.exec_replace();
|
process.exec_replace()
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(()) => Ok(None),
|
|
||||||
Err(e) => {
|
|
||||||
let err = e.downcast::<ProcessError>()?;
|
|
||||||
Ok(Some(err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
//! Tests for configuration values that point to programs.
|
//! Tests for configuration values that point to programs.
|
||||||
|
|
||||||
use cargo_test_support::rustc_host;
|
use cargo_test_support::{basic_lib_manifest, no_such_file_err_msg, project, rustc_host};
|
||||||
use cargo_test_support::{basic_lib_manifest, project};
|
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
fn pathless_tools() {
|
fn pathless_tools() {
|
||||||
@ -274,7 +273,18 @@ fn custom_runner_env() {
|
|||||||
p.cargo("run")
|
p.cargo("run")
|
||||||
.env(&key, "nonexistent-runner --foo")
|
.env(&key, "nonexistent-runner --foo")
|
||||||
.with_status(101)
|
.with_status(101)
|
||||||
.with_stderr_contains("[RUNNING] `nonexistent-runner --foo target/debug/foo[EXE]`")
|
.with_stderr(&format!(
|
||||||
|
"\
|
||||||
|
[COMPILING] foo [..]
|
||||||
|
[FINISHED] dev [..]
|
||||||
|
[RUNNING] `nonexistent-runner --foo target/debug/foo[EXE]`
|
||||||
|
[ERROR] could not execute process `nonexistent-runner --foo target/debug/foo[EXE]` (never executed)
|
||||||
|
|
||||||
|
Caused by:
|
||||||
|
{}
|
||||||
|
",
|
||||||
|
no_such_file_err_msg()
|
||||||
|
))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user