generated from emilk/eframe_template
-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Use color-eyre for error handling and add a log window #83
Merged
Conversation
This file contains 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
To set the verbosity in web builds, we need to use `.lib_verbosity`, not `.verbosity`. There will still be no backtrace displayed because we are using the `panic_abort` panic handler instead of the normal `panic_unwind` handler that native builds use. There is currently no support for `panic_unwind` on the `wasm32-unknown-unknown` target unless we use `no_std`.
Moving to color-eyre allows us to use color-backtrace for formatting errors, which anyhow does not support. It's otherwise essentially the same as anyhow but with some peculiar and confusing names in the API changed.
The terminal now immediately resizes to the correct size instead of starting at the wrong size and taking several frames to resize. The terminal size controls have been moved to the top of the terminal window so that if the terminal is too big to fit on the screen, the user can still access the controls to make it smaller. Also, the format is now COLS x ROWS instead of ROWS x COLS. The terminal also handles focus and hover correctly now. It won't change the cursor unless the terminal is hovered, and it won't accept keyboard input unless it's focused. Also, the terminal no longer requests a rerender every frame. Now, it only does that if the terminal's contents have been updated. For the output window, this is done by making the tracing writer call `ctx.request_repaint()` every time it writes to the log. For shells, this is done by doing the same whenever there is at least one terminal action received by the thread.
This is so that the logs accurately display where the toast was created from instead of displaying the location as somewhere in toasts.rs.
Speak2Erase
requested changes
Jan 2, 2024
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 think this was a problem from before this pull request, but I'll fix it here anyways |
Alright, it should be fixed |
Speak2Erase
approved these changes
Jan 2, 2024
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.
Looks good to me!
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.
Connections
Description
This pull request adds more detailed errors to the filesystem crate and switches the error reporting library from anyhow to color-eyre, which is basically the same thing as anyhow except it uses color-backtrace for error and panic reporting and supports a few extra features like adding extra messages (suggestions, etc.) to reports and printing spantraces from tracing-error.
Migrating from anyhow to color-eyre is easy:
anyhow::Error
->color_eyre::Report
anyhow::Result
->color_eyre::Result
anyhow::bail!
->color_eyre::eyre::bail!
anyhow::anyhow!
->color_eyre::eyre::eyre!
anyhow::Context
->color_eyre::eyre::WrapErr
.context("Message")
->.wrap_err("Message")
.with_context(|| "Message")
->.wrap_err_with(|| "Message")
Errors are now shown both as toasts and as color-eyre formatted reports in the console. All other toast messages are redirected to the console as well.
There would be a backtrace shown in native builds. There are still no backtraces on WebAssembly because we're using the
panic_abort
panic handler instead ofpanic_unwind
, which is not supported except inno_std
environments (rust-lang/rust#118168). Theoretically it should be possible to get backtraces withpanic_abort
by passing-Cforce-unwind-tables=yes
to rustc, but this doesn't seem to be supported for WebAssembly either.The toast functions in crates/core/src/toasts.rs have been replaced with macros:
luminol_core::info!(update_state.toasts, "message")
luminol_core::warn!(update_state.toasts, "message")
luminol_core::basic!(update_state.toasts, "message")
for generic toasts and
luminol_core::error!(update_state.toasts, report)
for errors wherereport
is acolor_eyre::Report
. This is so that the log shows the actual location where a toast was created instead of showing every toast as being created in toasts.rs.There's also a log window in native builds now that the error messages will show up in, since I don't expect most people will have an external console window open when running Luminol. It can be found at the bottom of the Debug menu in the top bar.
Checklist
cargo fmt
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
cargo build --release
trunk build --release