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

Crash reporter #87

Merged
merged 44 commits into from
Feb 2, 2024
Merged

Crash reporter #87

merged 44 commits into from
Feb 2, 2024

Conversation

white-axe
Copy link
Collaborator

Connections

Description
Luminol now restarts after panicking on both native and web platforms. After restarting, it shows a window asking the user if they want to send the crash report to the developers. The crash report is a JSON object sent as a POST request; it contains the panic message as well as the Git revision, target triple and profile (debug/release).

It reports to http://localhost:3246 right now for easy testing. This should be changed in crates/ui/src/windows/reporter.rs to a real URL at some point. Don't worry about CORS - web builds can send crash reports even if the endpoint doesn't set CORS headers.

Restarting after panics is done on Unix-like systems by using one of the exec system calls to replace the current process without creating a new one. On Windows, it spawns a background process and then terminates the original one. For WebAssembly, it's done by reloading the WebAssembly modules. Reports are persisted across restarts in native builds by creating a temporary file and in web builds by saving the report as a JavaScript global variable.

I was originally going to try using std::panic::catch_unwind to catch panics, but this doesn't work in WebAssembly due to the panic_abort panic handler and it causes segfaults and other signs of undefined behaviour in native builds somewhere inside of winit.

There are also some related improvements to web builds:

  • Luminol now completely caches itself after loading for the first time so that the browser doesn't have to download the WebAssembly module again every time a panic occurs. No internet access is required after the first page load.
  • The Git revision is now determined from the Trunk hooks instead of with the git-version macro so that it can correctly determine if the code has uncommitted changes. It should now append or not append "-modified" to the Git revision properly instead of always appending "-modified" regardless of whether there are uncommitted changes.
  • Event handlers for mouse and keyboard and the like are now unregistered after panics for performance reasons.
  • Clippy no longer errors out when checking luminol-web, so we can now see clippy lints for crates that depend on luminol-web.

Testing
Right now, a panic can be triggered by attempting to create or edit events in the map editor.

Testing for reception of reports on localhost can be done with a simple echo server like this one: https://github.com/cdfuller/echo-server. If you use this one in particular, make sure to run it with the -v flag so that it prints the contents of requests. Whatever echo server is used, test that it is able to receive reports from both native and web builds of Luminol.

It would also be a good idea to check that a real, internet-facing server is able to receive reports, especially that one that does not support CORS is able to receive reports from a web build of Luminol.

Checklist

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

The program's first argument is not guaranteed to be a path to the
current executable.

Also, at least on Linux, `std::env::current_exe()` is able to correctly
find the new location of the executable if the user moves the executable
before the panic handler runs.
Setting this to `forbid` seems to break clippy when using wasm-bindgen.
I'm setting this to `warn` so we can see clippy lints for crates that
depend on luminol-web in web builds.
Without this, the Git version will always have "-modified" at the end in
web builds even if the code is unmodified, because the Trunk hooks
modify .cargo/config.toml.
Luminol can now be run offline after loading it in a browser once.
@white-axe white-axe requested a review from a team as a code owner January 12, 2024 02:24
@white-axe white-axe added the enhancement New feature or request label Jan 12, 2024
This fixes a problem where sometimes, either cross-origin isolation
would not be enabled at all or sw.js would have its own COEP (but not
the COEP for other files) set to require-corp instead of credentialless.
This would be fixed by refreshing the page a number of times.

Now, COI should always be enabled and the COEP for sw.js should always
be credentialless, without the user having to refresh the page: the page
is automatically refreshed.
Haha, turns out we don't even need credentialless COEP to send no-cors
requests! The require-corp COEP works just fine.
After further testing, it seems Firefox does require credentialless COEP
for this type of no-cors request, so Chromium allowing it is probably a
bug.
This fixes some edge cases I experienced when testing in Firefox where
the user refreshing the page sometimes causes the page's COEP to revert
to "require-corp" (the service worker is supposed to set it to
"credentialless").

I hate web development so much.
This fixes a bug where updating one of the HTML or JavaScript files
(which changes the output of the `luminol_core::version!` macro) doesn't
cause every crate that uses the `luminol_core::version!` macro to be
recompiled, resulting in parts of Luminol getting different Git revision
strings from this macro.
crates/core/Cargo.toml Show resolved Hide resolved
@white-axe white-axe requested a review from somedevfox January 17, 2024 16:58
This prevents the Git revision from being miscalculated if some of the
crates are at a different version than others.
@white-axe
Copy link
Collaborator Author

Since I'd already changed how the Git version is calculated in web builds, I've also moved the Git version into the luminol crate (#89). This will prevent the version from being different in different crates if the crates are not all at the same revision.

@white-axe white-axe requested a review from melody-rs January 31, 2024 17:28
@white-axe
Copy link
Collaborator Author

I can't merge this until @somedevfox approves

@somedevfox somedevfox merged commit 58c5a2b into Astrabit-ST:dev Feb 2, 2024
5 checks passed
@white-axe white-axe deleted the reporter branch February 2, 2024 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash webhook
3 participants