@@ -182,7 +182,17 @@ pub fn exit_with_error(err: CliError, shell: &mut Shell) -> ! {
182182/// Displays an error, and all its causes, to stderr.
183183pub fn display_error ( err : & Error , shell : & mut Shell ) {
184184 debug ! ( "display_error; err={:?}" , err) ;
185- _display_error ( err, shell, true ) ;
185+
186+ let mut errs = error_chain ( err, shell. verbosity ( ) ) ;
187+ let Some ( first) = errs. next ( ) else {
188+ return ;
189+ } ;
190+ drop ( shell. error ( & first) ) ;
191+ for err in errs {
192+ drop ( writeln ! ( shell. err( ) , "\n Caused by:" ) ) ;
193+ drop ( write ! ( shell. err( ) , "{}" , indented_lines( & err. to_string( ) ) ) ) ;
194+ }
195+
186196 if err
187197 . chain ( )
188198 . any ( |e| e. downcast_ref :: < InternalError > ( ) . is_some ( ) )
@@ -204,7 +214,16 @@ pub fn display_error(err: &Error, shell: &mut Shell) {
204214pub fn display_warning_with_error ( warning : & str , err : & Error , shell : & mut Shell ) {
205215 drop ( shell. warn ( warning) ) ;
206216 drop ( writeln ! ( shell. err( ) ) ) ;
207- _display_error ( err, shell, false ) ;
217+
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}" ) ) ;
223+ for err in errs {
224+ drop ( writeln ! ( shell. err( ) , "\n Caused by:" ) ) ;
225+ drop ( write ! ( shell. err( ) , "{}" , indented_lines( & err. to_string( ) ) ) ) ;
226+ }
208227}
209228
210229fn error_chain ( err : & Error , verbosity : Verbosity ) -> impl Iterator < Item = & dyn std:: fmt:: Display > {
@@ -219,18 +238,3 @@ fn error_chain(err: &Error, verbosity: Verbosity) -> impl Iterator<Item = &dyn s
219238 . take_while ( |err| !err. is :: < AlreadyPrintedError > ( ) )
220239 . map ( |err| err as & dyn std:: fmt:: Display )
221240}
222-
223- fn _display_error ( err : & Error , shell : & mut Shell , as_err : bool ) {
224- for ( i, err) in error_chain ( err, shell. verbosity ( ) ) . enumerate ( ) {
225- if i == 0 {
226- if as_err {
227- drop ( shell. error ( & err) ) ;
228- } else {
229- drop ( writeln ! ( shell. err( ) , "{}" , err) ) ;
230- }
231- } else {
232- drop ( writeln ! ( shell. err( ) , "\n Caused by:" ) ) ;
233- drop ( write ! ( shell. err( ) , "{}" , indented_lines( & err. to_string( ) ) ) ) ;
234- }
235- }
236- }
0 commit comments