From 62d1fc31e2d09bf0131c5188ad6c9b9f7a764cc2 Mon Sep 17 00:00:00 2001 From: iovxw Date: Wed, 20 Sep 2023 19:12:46 +0800 Subject: [PATCH] Update to error::Report, fix nightly builds --- src/main.rs | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/src/main.rs b/src/main.rs index 379eb89b..e2f47377 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,6 @@ -#![feature(error_generic_member_access, provide_any)] +#![feature(error_reporter)] #![recursion_limit = "256"] -use std::backtrace::Backtrace; use std::convert::TryInto; use std::env; use std::panic; @@ -159,29 +158,10 @@ fn init_proxy() -> Option { } fn print_error(err: E) { - eprintln!("Error: {}", err); - - let mut err: &dyn std::error::Error = &err; - let mut deepest_backtrace = err.request_ref::(); - if let Some(e) = err.source() { - eprintln!("\nCaused by:"); - let multiple = e.source().is_some(); - let mut line_counter = 0..; - while let (Some(e), Some(line)) = (err.source(), line_counter.next()) { - if multiple { - eprint!("{: >4}: ", line) - } else { - eprint!(" ") - }; - eprintln!("{}", e); - if let Some(backtrace) = e.request_ref::() { - deepest_backtrace = Some(backtrace); - } - err = e; - } - } - - if let Some(backtrace) = deepest_backtrace { - eprintln!("\nBacktrace:\n{}", backtrace); - } + eprintln!( + "Error: {}", + std::error::Report::new(err) + .pretty(true) + .show_backtrace(true) + ); }