mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 20:01:08 +00:00
Print version when panic (#3608)
* Print version when panic * Fix tests.
This commit is contained in:
committed by
Gavin Wood
parent
634ca73e50
commit
981b3c79ee
@@ -77,7 +77,7 @@ const NODE_KEY_ED25519_FILE: &str = "secret_ed25519";
|
||||
|
||||
/// Executable version. Used to pass version information from the root crate.
|
||||
pub struct VersionInfo {
|
||||
/// Implemtation name.
|
||||
/// Implementaiton name.
|
||||
pub name: &'static str,
|
||||
/// Implementation version.
|
||||
pub version: &'static str,
|
||||
@@ -191,13 +191,13 @@ where
|
||||
I: IntoIterator,
|
||||
<I as IntoIterator>::Item: Into<std::ffi::OsString> + Clone,
|
||||
{
|
||||
panic_handler::set(version.support_url);
|
||||
|
||||
let full_version = service::config::full_version_from_strs(
|
||||
version.version,
|
||||
version.commit
|
||||
);
|
||||
|
||||
panic_handler::set(version.support_url, &full_version);
|
||||
|
||||
let matches = CoreParams::<CC, RP>::clap()
|
||||
.name(version.executable_name)
|
||||
.author(version.author)
|
||||
|
||||
@@ -494,7 +494,7 @@ mod tests {
|
||||
execute_with_proof_failure(&remote_client, 2, "Core_version");
|
||||
|
||||
// check that proof check doesn't panic even if proof is incorrect AND panic handler is set
|
||||
panic_handler::set("TEST");
|
||||
panic_handler::set("TEST", "1.2.3");
|
||||
execute_with_proof_failure(&remote_client, 2, "Core_version");
|
||||
}
|
||||
|
||||
|
||||
@@ -51,8 +51,13 @@ enum OnPanic {
|
||||
///
|
||||
/// The `bug_url` parameter is an invitation for users to visit that URL to submit a bug report
|
||||
/// in the case where a panic happens.
|
||||
pub fn set(bug_url: &'static str) {
|
||||
panic::set_hook(Box::new(move |c| panic_hook(c, bug_url)));
|
||||
pub fn set(bug_url: &'static str, version: &str) {
|
||||
panic::set_hook(Box::new({
|
||||
let version = version.to_string();
|
||||
move |c| {
|
||||
panic_hook(c, bug_url, &version)
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
macro_rules! ABOUT_PANIC {
|
||||
@@ -124,7 +129,7 @@ impl Drop for AbortGuard {
|
||||
}
|
||||
|
||||
/// Function being called when a panic happens.
|
||||
fn panic_hook(info: &PanicInfo, report_url: &'static str) {
|
||||
fn panic_hook(info: &PanicInfo, report_url: &'static str, version: &str) {
|
||||
let location = info.location();
|
||||
let file = location.as_ref().map(|l| l.file()).unwrap_or("<unknown>");
|
||||
let line = location.as_ref().map(|l| l.line()).unwrap_or(0);
|
||||
@@ -147,6 +152,8 @@ fn panic_hook(info: &PanicInfo, report_url: &'static str) {
|
||||
let _ = writeln!(stderr, "");
|
||||
let _ = writeln!(stderr, "====================");
|
||||
let _ = writeln!(stderr, "");
|
||||
let _ = writeln!(stderr, "Version: {}", version);
|
||||
let _ = writeln!(stderr, "");
|
||||
let _ = writeln!(stderr, "{:?}", backtrace);
|
||||
let _ = writeln!(stderr, "");
|
||||
let _ = writeln!(
|
||||
@@ -169,14 +176,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn does_not_abort() {
|
||||
set("test");
|
||||
set("test", "1.2.3");
|
||||
let _guard = AbortGuard::force_unwind();
|
||||
::std::panic::catch_unwind(|| panic!()).ok();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn does_not_abort_after_never_abort() {
|
||||
set("test");
|
||||
set("test", "1.2.3");
|
||||
let _guard = AbortGuard::never_abort();
|
||||
let _guard = AbortGuard::force_abort();
|
||||
std::panic::catch_unwind(|| panic!()).ok();
|
||||
|
||||
Reference in New Issue
Block a user