fix(engine): propagate history errors instead of panicking - #1173
Open
kronberger-droid wants to merge 2 commits into
Open
fix(engine): propagate history errors instead of panicking#1173kronberger-droid wants to merge 2 commits into
kronberger-droid wants to merge 2 commits into
Conversation
…rror handling") `impl From<ReedlineError> for io::Error` (unwrapping the `IOError` variant so the kind survives) lets the nine history sites in `engine.rs` use `?`. `run_history_commands`, `previous_history`, `next_history`, `up_command` and `down_command` grow `io::Result<()>`; all their callers already sit in `io::Result` fns, so `read_line` now returns `Err` where it used to panic. `history.save` in `submit_buffer` is left for the next commit, since failing there would lose the submitted command.
`submit_buffer` was the last `expect("todo: error handling")` and the one
where `?` is wrong: `read_line` returning `Err` would drop the command
the user just typed over a history write. Instead the entry is treated
like an excluded one (`FILTERED_ITEM_ID`, `history_excluded_item`), so
Up still recalls it and `update_last_command_context` updates it in
memory, and the error is stashed for `Reedline::take_history_save_error`.
Additive API; cleared on read, set at most once per `read_line`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The ten
expect("todo: error handling")inengine.rsall sit on history calls:HistoryCursor::back/forward,history.search,history.save.Nine of them are on navigation or printing paths inside
io::Resultfns already, so withimpl From<ReedlineError> for io::Error(theIOErrorvariant is unwrapped so its kind survives) they become?.run_history_commands,previous_history,next_history,up_commandanddown_commandgrowio::Result<()>; their callers arehandle_editor_event/handle_history_search_event, which already returnio::Result.read_linethus returnsErrwhere it used to panic. No change to its signature.The tenth,
history.saveinsubmit_buffer, is the one where?is wrong: anErrfromread_linewould drop the command the user just typed over a history write.Instead the entry is treated like an excluded one (
FILTERED_ITEM_ID,history_excluded_item), so Up still recalls it andupdate_last_command_contextupdates it in memory, and the error is stashed.New additive API:
Reedline::take_history_save_error() -> Option<ReedlineError>, cleared on read, set at most once perread_line.A caller that does not ask loses nothing; nushell can decide later whether to warn.
Before
A failing history backend panics the shell on Up/Down, ctrl-r, or Enter.
After
Navigation and search failures come back as
io::Errorfromread_line; a failed save still returnsSignal::Success(line)and the error waits intake_history_save_error.