Skip to content

fix: ensure loading_screen! generated thread joins before exiting patch-hub#122

Closed
lorenzoberts wants to merge 1 commit intokworkflow:unstablefrom
lorenzoberts:lorenzo/solve-cursor-missing
Closed

fix: ensure loading_screen! generated thread joins before exiting patch-hub#122
lorenzoberts wants to merge 1 commit intokworkflow:unstablefrom
lorenzoberts:lorenzo/solve-cursor-missing

Conversation

@lorenzoberts
Copy link
Collaborator

This PR fixes #74.

Besides what I've described in the commit message, I would like to point out that this issue is a great example why we should always avoid unwraps and gracefully handle errors. Even though the problem was not caused by any unwraps, the problematic behavior will continue to happen if the code panics before joining the loading screen thread.

I chose to focus on resolving the bug itself, which is why I didn’t remove any unwrapping from the related logic. Additionally, as I mentioned in the commit message, it’s important for us to pay attention to how Rust handles closures. I’m not sure if what we were doing was intentional, but at least for me, it’s counterintuitive that the ? and return inside a closure don’t apply to the closure itself. @davidbtadokoro , if you can remember any other places where we might have handled this incorrectly, let me know, and I can fix it.

…ch-hub

This commit fixes the cursor becoming invisible when crash occur during loading.
The problem was caused by not joining the thread generated by loading_screen!
before handling the error (e.g exiting patch-hub).
The solution was achieved by the following changed:
1. Made the closure that's passed to the loading_screen! macro return a Result
instead of (), enabling proper handling of the result after joining the loading
thread.
2. Changed the closures to avoid propagating errors using the ? operator, as
in Rust, "?" and "return" are applied to the outer function instead of the
closure itself.

Closes: kworkflow#74

Signed-off-by: Lorenzo Bertin Salvador <lorenzobs@usp.br>
@lorenzoberts lorenzoberts force-pushed the lorenzo/solve-cursor-missing branch from e73747a to c196644 Compare March 15, 2025 23:20
@davidbtadokoro
Copy link
Collaborator

Hi @lorenzoberts. First of all, I am sorry about the delay 😓 I hate giving excuses, but things have been hectic in the last months...

Anyway, thank you so much for this awesome fix! I must confess that I had not many hopes on solving this bug, as I couldn't elaborate the cause of it, but your PR not only fixed it gracefully, but also made sense of it to me 😺

Thank you so much, great PR, and change merged into the unstable branch 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants