New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrapping run_repl with catch_unwind and restarting the repl on panic #11860
Conversation
Seems like this simple implementation should be enough to recover from most error states for two reasons:
Once cleaned up, I'd be willing to merge this and see how it goes. |
Actually, there are some init steps before running the actual REPL |
@ayax79 I'm not sure what I did but the shell is in a weird state now and I can't start nushell. I'm kind of wondering if there should be some crossterm reset that happens on panic before the repl is restarted? |
My initial theory was that since On another note,
|
Suggestions from chats with other people.
|
Per @kubouch's earlier suggestion I started working on building up a new EngineState for the repl. If I can get that to work, I am going see if I can at least copy some of the state from the previous EngineState. |
I just committed a version that creates a new EngineState. Can you see if it works better. |
I get the same thing as Kubouch with this
it just panics and restarts the repl forever. Some real-world panics.
I'll have to test next week on Windows more. |
This is weird as I would've assumed that a command like that would only hit the Nm... I just read help again, it's supposed to exit into an interactive shell. I think I can avoid this by just not passing in the command line args the second time, which is probably the correct behavior. |
The case of running with -e is fixed now. I am going to spend some more time testing tomorrow. I also want to copy over environment variables from the old engine state, I think that would be safe. |
One approach Sophia suggested was to only wrap the |
The contents of the loop block in run_repl are now wrapped in a catch_unwind. It does seem to work better, though I haven't tested it too heavily yet. |
9890e0b
to
d84b4b3
Compare
@kubouch, let me know what you think. Also, to double check:
You are suggesting that we keep the catch_unwind that wraps |
This is how I repro on Windows.
|
@fdncred In the meantime, I'm wondering if I remove the now mostly redundant catch_unwind in main.rs if things start working. Once I'm back to my desk, I'll make that change and ping you. |
Sounds good. |
This seems to work with the current changes for me on Windows. |
@ayax79 I still can't get it to work. My repro above still breaks it. It's trashing terminal.exe for some reason. I have to completely close out of Windows Terminal to restart. Even things like |
For those watching, jack, ian and i were playing around with this in open-mic on discord and discovered that this (my reported problem above) is indeed and issue but NOT related to jack's PR here. This PR seems to work just fine. However, if you do a ls of \.\pipe\ on windows in nushell, your Windows Terminal will be left in a broken state. Again, it's unrelated to this PR so I feel fine saying we could move forward with landing as long as people have tested on Mac and Linux. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do some testing on Linux today or tomorrow. Just one thing to note in the mean time:
I added |
Yep this is perfect, thanks @ayax79 ! There are few other things that I would like to see changed, but they're probably best left for separate PRs. For future reference if anyone is interested:
Otherwise, I did some testing on Linux, and it looks good! |
Let's move forward with this PR and keep working on it. |
I have PR for the configuration case in #11935 I can definitely capture the Err, I opted not too in this request in case it changed any desired behavior. Should certain errors kill the shell? |
@ayax79 Great, thanks for that PR!
Ideally, no error in There's no need for you to tackle this, but of course, feel free to give it a shot if you feel like it! |
Handle all errors that happen within the REPL loop, display warning or error messages, and return defaults where necessary. This addresses @IanManske [Comment Item 1](#11860 (comment)) in #11860 --------- Co-authored-by: Jack Wright <jack.wright@disqo.com>
…ushell#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>
Handle all errors that happen within the REPL loop, display warning or error messages, and return defaults where necessary. This addresses @IanManske [Comment Item 1](nushell#11860 (comment)) in nushell#11860 --------- Co-authored-by: Jack Wright <jack.wright@disqo.com>
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.