Comments (2)
thanks @kdar this is really helpful, will try this out
from human-panic.
Maybe not ideal, but you could get the filename via handle_dump, and then read it and display it to the user.
Another option is to use code similar to #55 (comment) and not use human_panic. Instead of logging to a file you just build and use the string. Then you can actually get the panic message as well.
For reference, this is code I'm using in my own project:
use std::panic::{self, PanicInfo};
use backtrace::Backtrace;
pub fn setup() {
panic::set_hook(Box::new(move |info: &PanicInfo| {
let mut msg = String::new();
let os = if cfg!(target_os = "windows") {
"Windows"
} else if cfg!(target_os = "linux") {
"Linux"
} else if cfg!(target_os = "macos") {
"Mac OS"
} else if cfg!(target_os = "android") {
"Android"
} else {
"Unknown"
};
msg.push_str(&format!("Name: {}\n", env!("CARGO_PKG_NAME")));
msg.push_str(&format!("Version: {}\n", env!("CARGO_PKG_VERSION")));
msg.push_str(&format!("Operating System: {}\n", os));
if let Some(inner) = info.payload().downcast_ref::<&str>() {
msg.push_str(&format!("Cause: {}.\n", &inner));
}
match info.location() {
Some(location) => msg.push_str(&format!(
"Location: in file '{}' at line {}\n",
location.file(),
location.line()
)),
None => msg.push_str("Panic location unknown.\n"),
};
msg.push_str(&format!("Message: {}\n", info));
msg.push_str(&format!("\n{:#?}\n", Backtrace::new()));
// Do something with msg...
}));
}
from human-panic.
Related Issues (20)
- consider using/copying backtrace-ext to more properly filter the backtrace
- Dependency Dashboard
- Remove `toml` dependency HOT 2
- Human panic only when it's intended for humans HOT 7
- 🙋 Suggestion: Start printing backtrace from panic's position HOT 1
- Custom error message HOT 6
- Where is the panic! log message ? HOT 4
- Update to Rust 2018
- Cause (Payload) Does Not Support Strings
- New (point) release? HOT 6
- Custom human error printer
- User should can set selfdefine panic file path in setup macro
- v1.0.2 breaks wasm-pack v0.9.1 because of #45 HOT 1
- 🐛 Changelog out of date, missing entries for 1.0.1 and 1.0.3
- Update documents on the https://crates.io/crates/human-panic.
- Missing doc on exact usage of this crate HOT 1
- Fallback to repository if homepage is absent
- Minimum Supported Rust Version isn't supported HOT 1
- metadata! doesn't use $crate
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from human-panic.