Skip to content
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
merged 42 commits into from
Jan 2, 2024

Conversation

white-axe
Copy link
Collaborator

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.

Screenshot

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 of panic_unwind, which is not supported except in no_std environments (rust-lang/rust#118168). Theoretically it should be possible to get backtraces with panic_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 where report is a color_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

  • Run cargo fmt.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo build --release
  • If applicable, run trunk build --release

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.
@white-axe white-axe added enhancement New feature or request code style labels Jan 2, 2024
@white-axe white-axe requested a review from a team as a code owner January 2, 2024 00:06
Copy link
Member

@Speak2Erase Speak2Erase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After failing to open a project from the get started tab, Luminol thinks the project is opened
image

@white-axe
Copy link
Collaborator Author

I think this was a problem from before this pull request, but I'll fix it here anyways

@white-axe
Copy link
Collaborator Author

Alright, it should be fixed

Speak2Erase

This comment was marked as duplicate.

Copy link
Member

@Speak2Erase Speak2Erase left a 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!

@Speak2Erase Speak2Erase merged commit 3471b50 into Astrabit-ST:dev Jan 2, 2024
5 checks passed
@white-axe white-axe deleted the error-handling branch January 2, 2024 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code style enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improved error reports
2 participants