Skip to content

Commit 2fd5892

Browse files
committed
fix(cli): Use Shell::print_report for warning with errors
1 parent 940bf01 commit 2fd5892

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/cargo/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,16 @@ pub fn display_error(err: &Error, shell: &mut Shell) {
212212
/// Displays a warning, with an error object providing detailed information
213213
/// and context.
214214
pub fn display_warning_with_error(warning: &str, err: &Error, shell: &mut Shell) {
215-
drop(shell.warn(warning));
216-
drop(writeln!(shell.err()));
215+
use annotate_snippets::*;
217216

218-
let mut errs = error_chain(err, shell.verbosity());
219-
let Some(first) = errs.next() else {
220-
return;
221-
};
222-
drop(writeln!(shell.err(), "{first}"));
217+
let mut group = Group::with_title(Level::WARNING.primary_title(warning));
218+
219+
let errs = error_chain(err, shell.verbosity());
223220
for err in errs {
224-
drop(writeln!(shell.err(), "\nCaused by:"));
225-
drop(write!(shell.err(), "{}", indented_lines(&err.to_string())));
221+
group = group.element(Level::ERROR.with_name("caused by").message(err.to_string()));
226222
}
223+
224+
drop(shell.print_report(&[group], true));
227225
}
228226

229227
fn error_chain(err: &Error, verbosity: Verbosity) -> impl Iterator<Item = &dyn std::fmt::Display> {

tests/testsuite/workspaces.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,6 @@ fn new_warning_with_corrupt_ws() {
11201120
1 | asdf
11211121
| ^
11221122
[WARNING] compiling this new package may not work due to invalid workspace configuration
1123-
11241123
[NOTE] see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
11251124
11261125
"#]]).run();

0 commit comments

Comments
 (0)