forked from extern/nushell
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:
@ -915,6 +915,20 @@ impl EngineState {
|
||||
pub fn set_startup_time(&mut self, startup_time: i64) {
|
||||
self.startup_time = startup_time;
|
||||
}
|
||||
|
||||
pub fn recover_from_panic(&mut self) {
|
||||
if Mutex::is_poisoned(&self.repl_state) {
|
||||
self.repl_state = Arc::new(Mutex::new(ReplState {
|
||||
buffer: "".to_string(),
|
||||
cursor_pos: 0,
|
||||
}));
|
||||
}
|
||||
if Mutex::is_poisoned(&self.regex_cache) {
|
||||
self.regex_cache = Arc::new(Mutex::new(LruCache::new(
|
||||
NonZeroUsize::new(REGEX_CACHE_SIZE).expect("tried to create cache of size zero"),
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for EngineState {
|
||||
|
Reference in New Issue
Block a user