|
140 | 140 | //! [Cargo Contributor Guide]: https://doc.crates.io/contrib/
|
141 | 141 |
|
142 | 142 | use crate::core::Shell;
|
| 143 | +use crate::core::shell::Verbosity; |
143 | 144 | use crate::core::shell::Verbosity::Verbose;
|
144 | 145 | use anyhow::Error;
|
145 | 146 | use tracing::debug;
|
@@ -206,18 +207,21 @@ pub fn display_warning_with_error(warning: &str, err: &Error, shell: &mut Shell)
|
206 | 207 | _display_error(err, shell, false);
|
207 | 208 | }
|
208 | 209 |
|
| 210 | +fn error_chain(err: &Error, verbosity: Verbosity) -> impl Iterator<Item = &dyn std::fmt::Display> { |
| 211 | + err.chain() |
| 212 | + .take_while(move |err| { |
| 213 | + // If we're not in verbose mode then only print cause chain until one |
| 214 | + // marked as `VerboseError` appears. |
| 215 | + // |
| 216 | + // Generally the top error shouldn't be verbose, but check it anyways. |
| 217 | + verbosity == Verbose || !err.is::<VerboseError>() |
| 218 | + }) |
| 219 | + .take_while(|err| !err.is::<AlreadyPrintedError>()) |
| 220 | + .map(|err| err as &dyn std::fmt::Display) |
| 221 | +} |
| 222 | + |
209 | 223 | fn _display_error(err: &Error, shell: &mut Shell, as_err: bool) {
|
210 |
| - for (i, err) in err.chain().enumerate() { |
211 |
| - // If we're not in verbose mode then only print cause chain until one |
212 |
| - // marked as `VerboseError` appears. |
213 |
| - // |
214 |
| - // Generally the top error shouldn't be verbose, but check it anyways. |
215 |
| - if shell.verbosity() != Verbose && err.is::<VerboseError>() { |
216 |
| - break; |
217 |
| - } |
218 |
| - if err.is::<AlreadyPrintedError>() { |
219 |
| - break; |
220 |
| - } |
| 224 | + for (i, err) in error_chain(err, shell.verbosity()).enumerate() { |
221 | 225 | if i == 0 {
|
222 | 226 | if as_err {
|
223 | 227 | drop(shell.error(&err));
|
|
0 commit comments