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

Add a function which sets up the "Console Error Panic Hook" so thatg debugging is easier #512

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ edition = "2018"
livesplit-core = { path = "..", default-features = false, features = ["std"] }
serde_json = "1.0.8"
time = { version = "0.3.4" }
console_error_panic_hook = { version = "0.1.7", optional = true }

[features]
default = ["image-shrinking"]
image-shrinking = ["livesplit-core/image-shrinking"]
software-rendering = ["livesplit-core/software-rendering"]
wasm-web = ["livesplit-core/wasm-web"]
wasm-web = ["livesplit-core/wasm-web", "console_error_panic_hook"]
Copy link
Collaborator

@CryZe CryZe May 23, 2022

Choose a reason for hiding this comment

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

I think this could be its own feature. I'm not sure if you always want this.

auto-splitting = ["livesplit-core/auto-splitting"]
11 changes: 11 additions & 0 deletions capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use std::{
ptr,
};

extern crate console_error_panic_hook;

pub mod analysis;
pub mod auto_splitting_runtime;
pub mod atomic_date_time;
Expand Down Expand Up @@ -193,3 +195,12 @@ pub extern "C" fn dealloc(ptr: *mut u8, cap: usize) {
pub extern "C" fn get_buf_len() -> usize {
OUTPUT_VEC.with(|v| v.borrow().len() - 1)
}


/// sets the console error panic hook
/// this means that when rust panics in wasm, the panic message will be sent to js console
#[cfg(feature = "wasm-web")]
#[no_mangle]
pub extern "C" fn initialize_debugging() {
console_error_panic_hook::set_once();
}