wrapping run_repl with catch_unwind and restarting the repl on panic (#11860)

Provides the ability to cleanly recover from panics, falling back to the
last known good state of EngineState and Stack. This pull request also
utilizes miette's panic handler for better formatting of panics.

<img width="642" alt="Screenshot 2024-02-21 at 08 34 35"
src="https://github.com/nushell/nushell/assets/56345/f81efaba-aa45-4e47-991c-1a2cf99e06ff">

---------

Co-authored-by: Jack Wright <jack.wright@disqo.com>
This commit is contained in:
Jack Wright
2024-02-22 10:14:10 -08:00
committed by GitHub
parent cf68334fa0
commit f17f857b1f
9 changed files with 521 additions and 361 deletions

View File

@ -216,6 +216,7 @@ pub(crate) fn parse_commandline_args(
std::process::exit(1);
}
#[derive(Clone)]
pub(crate) struct NushellCliArgs {
pub(crate) redirect_stdin: Option<Spanned<String>>,
pub(crate) login_shell: Option<Spanned<String>>,

View File

@ -53,6 +53,7 @@ fn get_engine_state() -> EngineState {
fn main() -> Result<()> {
let entire_start_time = std::time::Instant::now();
let mut start_time = std::time::Instant::now();
miette::set_panic_hook();
let miette_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |x| {
crossterm::terminal::disable_raw_mode().expect("unable to disable raw mode");