-
Notifications
You must be signed in to change notification settings - Fork 38
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
Properly handle final path errors #92
Conversation
Ah, good catch! I think I somehow thought that the question mark would only go up to the enclosing block, but it goes all the way up because the block is not a function. This same can be achieved with another TereAppState::init(settings, &warnings)
.and_then(|state| TereTui::init(state, &mut stderr))
// actually run the app and return the final path
.and_then(|mut ui| ui.main_event_loop())
.and_then(|final_path| Ok((final_path, warnings))) (note no semicolon at the end) I think we should also check the first question mark (at the end of chain producing Edit: oh, clippy tells me that it can be just .map(|final_path| (final_path, warnings)) |
Yeah for example if I delete (or rename) the history json file so I get the first run prompt, cancelling it prints
even though it should be just The full execution could be just chained together into a big sequence: stderr
.flush()
.map_err(TereError::from)
.and_then(|_| TereSettings::parse_cli_args(&cli_args))
.and_then(|(settings, warnings)| {
check_first_run_with_prompt(&settings, &mut stderr)?;
Ok((settings, warnings))
})
.and_then(|(settings, warnings)| {
TereAppState::init(settings, &warnings)
.and_then(|state| TereTui::init(state, &mut stderr))
// actually run the app and return the final path
.and_then(|mut ui| ui.main_event_loop())
.map(|final_path| (final_path, warnings))
}) I'm not sure why I didn't do it this way originally, maybe this is a bit harder to follow. |
Sorry for the late reply. That makes a lot of sense. Made the change in b9e06ef |
No worries, thanks! I'm currently down a rabbit hole of pseudo-terminals and terminal escape code handling, trying to write an integration test that would check the stdout/stderr. |
Definitely sounds interesting, let me know if you need any changes in the PR anytime soon! |
Okay I've added (failing) tests for the output of the whole app in 70d2686. I'll rebase this on top of it to check that the tests pass and then merge. |
b9e06ef
to
4de192c
Compare
Thanks! |
Fixes #91
The thing is, when the question mark is operator is used, the error is returned to
main
:tere/src/main.rs
Lines 69 to 72 in 8a97cd4
Thus the next error handling part is never executed:
tere/src/main.rs
Lines 80 to 96 in 8a97cd4
This PR removes the question mark operator and uses the good old match arms to return the error to the actual scope.