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

propose report feature #147

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
23 changes: 19 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub struct Metadata {
authors: Option<Cow<'static, str>>,
homepage: Option<Cow<'static, str>>,
support: Option<Cow<'static, str>>,
report: Option<Cow<'static, str>>,
}

impl Metadata {
Expand All @@ -73,6 +74,7 @@ impl Metadata {
authors: None,
homepage: None,
support: None,
report: None,
}
}

Expand Down Expand Up @@ -102,6 +104,15 @@ impl Metadata {
}
self
}

/// The report information
pub fn report(mut self, value: impl Into<Cow<'static, str>>) -> Self {
let value = value.into();
if !value.is_empty() {
self.report = value.into();
}
self
}
}

/// Initialize [`Metadata`]
Expand Down Expand Up @@ -133,6 +144,7 @@ macro_rules! metadata {
/// setup_panic!(Metadata::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
/// .authors("My Company Support <[email protected]>")
/// .homepage("support.mycompany.com")
/// .report("Please attach this file to your support request.")
/// .support("- Open a support request by email to [email protected]")
/// );
/// ```
Expand Down Expand Up @@ -224,6 +236,7 @@ fn write_msg<P: AsRef<Path>>(
authors,
homepage,
support,
report,
..
} = meta;

Expand All @@ -235,14 +248,16 @@ fn write_msg<P: AsRef<Path>>(
)?;
writeln!(
buffer,
"We have generated a report file at \"{}\". Submit an \
issue or email with the subject of \"{} Crash Report\" and include the \
report as an attachment.\n",
"We have generated a report file at \"{}\". {}\n",
match file_path {
Some(fp) => format!("{}", fp.as_ref().display()),
None => "<Failed to store file to disk>".to_owned(),
},
name
if let Some(report) = report {
report.to_string()
} else {
format!("Submit an issue or email with the subject of \"{} Crash Report\" and include the report as an attachment.", name)
}
)?;

if let Some(homepage) = homepage {
Expand Down
1 change: 1 addition & 0 deletions tests/custom-panic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ fn main() {
setup_panic!(metadata!()
.authors("My Company Support <[email protected]")
.homepage("www.mycompany.com")
.report("Please attach this crash report to your support request.")
.support("- Open a support request by email to [email protected]"));

println!("A normal log message");
Expand Down
2 changes: 1 addition & 1 deletion tests/custom-panic/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn release() {

custom-panic-test had a problem and crashed. To help us diagnose the problem you can send us a crash report.

We have generated a report file at "[..].toml". Submit an issue or email with the subject of "custom-panic-test Crash Report" and include the report as an attachment.
We have generated a report file at "[..].toml". Please attach this crash report to your support request.

- Homepage: www.mycompany.com
- Authors: My Company Support <[email protected]
Expand Down