-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement custom bug report forms (#2)
- Loading branch information
Showing
11 changed files
with
143 additions
and
228 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,33 @@ | ||
/target | ||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
/Cargo.lock | ||
|
||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
|
||
# Generated by Trunk | ||
dist/ | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# Some people use VSCode | ||
/.vscode/ | ||
|
||
# Some people use IntelliJ with Rust | ||
/.idea/ | ||
*.iml | ||
|
||
# Some people use pre-commit | ||
.pre-commit-config.yaml | ||
.pre-commit-config.yml | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
|
||
# Some people have Apple | ||
.DS_Store | ||
|
||
# Generated on wasm-pack failure | ||
**/unsupported.js |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// This is called from a button on the web example to allow the user to trigger a panic. | ||
#[no_mangle] | ||
pub extern "C" fn trigger_panic() { | ||
panic!("You triggered the panic!"); | ||
} | ||
|
||
fn main() { | ||
let my_form = format!( | ||
r#" | ||
<div style="display: flex; flex-direction: column; width: 100%; height: 100%; background-color: white; color: red"> | ||
This is a custom panic form! The stack trace is hidden from users. | ||
<textarea readonly id="{}" style="display: none;"></textarea> | ||
<br /> | ||
<input id="{}" type="submit" value="See Panic Info" style="width: fit-content;" /> | ||
</div> | ||
"#, | ||
web_panic_report::FORM_TEXTAREA_ID, | ||
web_panic_report::FORM_SUBMIT_ID | ||
); | ||
|
||
// Set the panic hook at the beginning of your program | ||
web_panic_report::set_hook_with("test-container", my_form, |panic_info| { | ||
web_sys::window() | ||
.unwrap() | ||
.alert_with_message(&panic_info.display.to_string()) | ||
.unwrap(); | ||
}); | ||
} |
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
File renamed without changes.
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,19 @@ | ||
use crate::WasmPanicInfo; | ||
|
||
/// The default form HTML. | ||
const FORM_HTML: &str = include_str!("form.html"); | ||
|
||
/// Set the panic hook, with a default form. | ||
/// | ||
/// # Params | ||
/// `container_id`: The ID of the HTML element that will be unmounted in favor of the form.\ | ||
/// `submit_callback`: The closure that will run when the user hits the send report button. | ||
/// | ||
/// # Panics | ||
/// This will panic (ironically) if the panic occurs in a headless environment. | ||
pub fn set_default_hook_with<F>(container_id: impl Into<String>, submit_callback: F) | ||
where | ||
F: Fn(&WasmPanicInfo) + Send + Sync + 'static, | ||
{ | ||
crate::set_hook_with(container_id, FORM_HTML, submit_callback) | ||
} |
Oops, something went wrong.