forked from atomCAD/atomCAD
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Register panic handler to receive and log unhandled exceptions to the…
… browser console.
- Loading branch information
Showing
8 changed files
with
109 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of | ||
// the MPL was not distributed with this file, You can obtain one at <http://mozilla.org/MPL/2.0/>. | ||
|
||
use crate::{App, Plugin}; | ||
|
||
/// Application plugin to perform platform-specific initialization. On the web backend, this sets | ||
/// up the console to catch and log unhandled panics. On all other backends, this does nothing. It | ||
/// is a default plugin included in [`App`] instances returned by [`App::new`]. | ||
pub struct PanicHandlerPlugin; | ||
|
||
/// When added to an [`App`] instance, ensures that any unhandled panics will be logged to the | ||
/// Javascript console on web platforms. Currently performs no other action on other backends. | ||
/// | ||
/// ``` | ||
/// # use atomcad_app::prelude::*; | ||
/// fn run(app: &mut App) { | ||
/// panic!("Oh no!"); | ||
/// } | ||
/// | ||
/// App::empty("Panic Handler Plugin".into()) | ||
/// .add_plugin(PanicHandlerPlugin) | ||
/// .run(); | ||
/// | ||
/// // Backtrace will be printed to debug console. | ||
/// ``` | ||
impl Plugin for PanicHandlerPlugin { | ||
/// Sets up the panic handler to log errors to the console on the web backend if we are running | ||
/// on WebAssembly, so that panics can be viewed in the browser's debug inspector. Otherwise | ||
/// does nothing. | ||
fn build(&self, _app: &mut App) { | ||
crate::platform_impl::setup_panic_handler(); | ||
} | ||
} | ||
|
||
// End of File |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of | ||
// the MPL was not distributed with this file, You can obtain one at <http://mozilla.org/MPL/2.0/>. | ||
|
||
/// Do nothing on non-web platforms. | ||
pub(crate) fn setup_panic_handler() {} | ||
|
||
// End of File |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of | ||
// the MPL was not distributed with this file, You can obtain one at <http://mozilla.org/MPL/2.0/>. | ||
|
||
// Only web implements any platform-specific application initialization code, at this time. All | ||
// other platforms pull the default implementation, which provides stub plugins that don't do | ||
// anything. | ||
|
||
#[cfg(target_family = "wasm")] | ||
mod web; | ||
#[cfg(target_family = "wasm")] | ||
#[allow(unused_imports)] | ||
pub use self::web::*; | ||
|
||
#[cfg(not(target_family = "wasm"))] | ||
mod default; | ||
#[cfg(not(target_family = "wasm"))] | ||
#[allow(unused_imports)] | ||
pub use self::default::*; | ||
|
||
// End of File |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of | ||
// the MPL was not distributed with this file, You can obtain one at <http://mozilla.org/MPL/2.0/>. | ||
|
||
/// Register the panic hook that logs errors to the Javascript console. | ||
pub(crate) fn setup_panic_handler() { | ||
console_error_panic_hook::set_once(); | ||
} | ||
|
||
// End of File |