Skip to content

Commit

Permalink
Use color-eyre for error handling and add a log window (Astrabit-ST#83)
Browse files Browse the repository at this point in the history
* fix: properly set log verbosity to full in web builds

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`.

* feat: show error context in error toasts

* refactor: use `anyhow::Result` instead of custom result types

* fix: fix web compilation errors

* chore: remove redundant `.into()`s

* feat: add more descriptive messages for filesystem errors

* feat: add context to archiver and host filesystems

* fix: properly propagate context for `std::io::Error`

* refactor: migrate from anyhow to color-eyre

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.

* feat: log color-eyre errors and panics to console

* chore: `color_eyre::eyre::Result` -> `color_eyre::Result`

* chore: remove `time` tokio feature and add `parking_lot` feature

* feat: add an output window in native builds for showing the log

* chore: remove tracing from root dependencies

* fix: output is now preserved after closing the output window

* chore: remove unused `output_term_rx` fields

* fix: make the output terminal larger

* fix: terminal UI improvements

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.

* feat: filter out useless backtrace frames

* chore: remove luminol-term from luminol-core dependencies

* fix: hide error when project loading is cancelled

* fix: filter out more backtrace frames

* fix: backtrace filters now filter out egui_dock

* refactor: toast functions are now macros

This is so that the logs accurately display where the toast was created
from instead of displaying the location as somewhere in toasts.rs.

* fix: filter out `T as core::` in backtrace filters

* fix: increase the default toast duration to 7 seconds

* chore: clippy

* chore: remove unused dependencies

* feat: add "Clear" and "Save to file" to output window

* refactor: rename the output window to log window

* fix: more terminal UI fixes

* fix: add more backtrace filters

* feat: add more error context to the filesystems

* feat: display git version in errors and panics

* fix: replace some `eprintln!` logging with proper errors

* refactor: split archiver/filesystem.rs into smaller files

* fix: reset terminal spacing on error

* fix: unload project when project fails to load

* fix: log buffer now has a bounded size

* fix: don't unmark data cache as modified until saving completes

* style: replace `.wrap_err(format!` with `.wrap_err_with(|| format!`

* style: add `#[doc(hidden)]` to `_e_add_version_section`
  • Loading branch information
white-axe authored Jan 2, 2024
1 parent 83de3eb commit 3471b50
Show file tree
Hide file tree
Showing 49 changed files with 3,310 additions and 1,509 deletions.
165 changes: 88 additions & 77 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ image = "0.24.7"
serde = { version = "1.0", features = ["derive"] }
alox-48 = { version = "0.4.2", default-features = false }
ron = "0.8.1"
serde_json = "1.0"
rust-ini = "0.20.0"

bytemuck = { version = "1.14.0", features = [
Expand All @@ -98,7 +97,7 @@ strum = { version = "0.25.0", features = ["derive"] }
paste = "1.0.14"
thiserror = "1.0.37"
bitflags = "2.4.0"
anyhow = "1.0"
color-eyre = "0.6.2"
puffin = "0.18"
raw-window-handle = "0.5.0"

Expand Down Expand Up @@ -127,7 +126,8 @@ itertools = "0.11.0"
rfd = "0.12.0"

rand = "0.8.5"
getrandom = { version = "0.2", features = ["js"] }

git-version = "0.3.9"

luminol-audio = { version = "0.4.0", path = "crates/audio/" }
luminol-components = { version = "0.4.0", path = "crates/components/" }
Expand All @@ -148,7 +148,6 @@ luminol-eframe.workspace = true
luminol-egui-wgpu.workspace = true
egui.workspace = true
egui_extras.workspace = true
epaint.workspace = true

wgpu.workspace = true

Expand All @@ -159,29 +158,29 @@ once_cell.workspace = true

image.workspace = true

crc = { version = "3.0.1", optional = true }

tracing-subscriber = "0.3.17"
color-backtrace = "0.6.0"
color-eyre.workspace = true

luminol-audio.workspace = true
luminol-core.workspace = true
luminol-config.workspace = true
luminol-data.workspace = true
luminol-filesystem.workspace = true
luminol-graphics.workspace = true
luminol-ui.workspace = true
# luminol-windows = { version = "0.1.0", path = "../windows/" }
# luminol-tabs = { version = "0.1.0", path = "../tabs/" }

poll-promise.workspace = true

camino.workspace = true

strum.workspace = true

zstd = "0.13.0"

async-std.workspace = true
futures-lite.workspace = true

git-version.workspace = true

# Native
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
steamworks = { version = "0.10.0", optional = true }
Expand All @@ -190,7 +189,7 @@ tokio = { version = "1.33", features = [
"macros",
"io-util",
"rt-multi-thread",
"time",
"parking_lot",
] } # *sigh*
luminol-term.workspace = true

Expand Down Expand Up @@ -237,7 +236,7 @@ optional = true
features = ["webgl"]

[features]
steamworks = ["dep:steamworks", "crc"]
steamworks = ["dep:steamworks"]
webgl = ["dep:wgpu"]

[target.'cfg(windows)'.build-dependencies]
Expand Down Expand Up @@ -284,6 +283,10 @@ opt-level = 3
[profile.dev.package.glam]
opt-level = 3

# Backtraces for color-eyre errors and panics
[profile.dev.package.backtrace]
opt-level = 3

# See why config is set up this way.
# https://bevy-cheatbook.github.io/pitfalls/performance.html#why-not-use---release

Expand Down
1 change: 1 addition & 0 deletions crates/audio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ parking_lot.workspace = true
camino.workspace = true
once_cell.workspace = true

color-eyre.workspace = true
thiserror.workspace = true

luminol-filesystem.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/audio/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ pub enum Error {
FileSystem(#[from] luminol_filesystem::Error),
}

pub type Result<T> = std::result::Result<T, Error>;
pub use color_eyre::Result;
9 changes: 1 addition & 8 deletions crates/components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,10 @@ syntect = { version = "5.1.0", default-features = false, features = [
"default-fancy",
] }

parking_lot.workspace = true

itertools.workspace = true

serde.workspace = true
color-eyre.workspace = true

once_cell.workspace = true
slab.workspace = true
qp-trie.workspace = true

anyhow.workspace = true

indextree = "4.6.0"
lexical-sort = "0.3.1"
9 changes: 7 additions & 2 deletions crates/components/src/filesystem_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,13 @@ where
ancestors.reverse();
let path = ancestors.join("/");

let mut subentries = self.filesystem.read_dir(path).unwrap_or_else(|e| {
update_state.toasts.error(e.to_string());
let mut subentries = self.filesystem.read_dir(&path).unwrap_or_else(|e| {
luminol_core::error!(
update_state.toasts,
e.wrap_err(format!(
"Error reading contents of directory {path} in filesystem view"
))
);
Vec::new()
});
subentries.sort_unstable_by(|a, b| {
Expand Down
4 changes: 2 additions & 2 deletions crates/components/src/map_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl MapView {
pub fn new(
update_state: &luminol_core::UpdateState<'_>,
map_id: usize,
) -> anyhow::Result<MapView> {
) -> color_eyre::Result<MapView> {
let map = update_state
.data
.get_or_load_map(map_id, update_state.filesystem);
Expand All @@ -91,7 +91,7 @@ impl MapView {
let events = map
.events
.iter()
.map(|(id, e)| -> anyhow::Result<_> {
.map(|(id, e)| -> color_eyre::Result<_> {
let sprite = luminol_graphics::Event::new(
&update_state.graphics,
update_state.filesystem,
Expand Down
10 changes: 8 additions & 2 deletions crates/components/src/sound_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ impl SoundTab {
pitch,
source,
) {
update_state.toasts.error(e.to_string());
luminol_core::error!(
update_state.toasts,
e.wrap_err("Error playing from audio file")
);
}
}

Expand Down Expand Up @@ -146,7 +149,10 @@ impl SoundTab {
pitch,
source,
) {
update_state.toasts.error(e.to_string());
luminol_core::error!(
update_state.toasts,
e.wrap_err("Error playing from audio file"),
);
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion crates/components/src/tilepicker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Tilepicker {
pub fn new(
update_state: &luminol_core::UpdateState<'_>,
map_id: usize, // FIXME
) -> anyhow::Result<Tilepicker> {
) -> color_eyre::Result<Tilepicker> {
let map = update_state
.data
.get_or_load_map(map_id, update_state.filesystem);
Expand Down
1 change: 0 additions & 1 deletion crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ workspace = true

[dependencies]
rust-ini.workspace = true

serde.workspace = true

strum.workspace = true
Expand Down
11 changes: 7 additions & 4 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ egui_dock = "0.9.0"
egui-notify = "0.11.0"
egui-modal = "0.3.1"

parking_lot.workspace = true
poll-promise.workspace = true

anyhow.workspace = true
tracing.workspace = true
color-eyre.workspace = true

camino.workspace = true
bitflags.workspace = true

itertools.workspace = true

strum.workspace = true
serde.workspace = true
alox-48.workspace = true

rand.workspace = true
getrandom.workspace = true

git-version.workspace = true

luminol-audio.workspace = true
luminol-config.workspace = true
Expand Down
Loading

0 comments on commit 3471b50

Please sign in to comment.