Skip to content

Commit d047a87

Browse files
authored
Merge pull request #138 from tisonkun/add-supports-links
feat: Add `support` section
2 parents 259bc32 + 2d6b767 commit d047a87

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/lib.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub struct Metadata {
6060
version: Cow<'static, str>,
6161
authors: Option<Cow<'static, str>>,
6262
homepage: Option<Cow<'static, str>>,
63+
support: Option<Cow<'static, str>>,
6364
}
6465

6566
impl Metadata {
@@ -70,6 +71,7 @@ impl Metadata {
7071
version: version.into(),
7172
authors: None,
7273
homepage: None,
74+
support: None,
7375
}
7476
}
7577

@@ -90,6 +92,15 @@ impl Metadata {
9092
}
9193
self
9294
}
95+
96+
/// The support information
97+
pub fn support(mut self, value: impl Into<Cow<'static, str>>) -> Self {
98+
let value = value.into();
99+
if !value.is_empty() {
100+
self.support = value.into();
101+
}
102+
self
103+
}
93104
}
94105

95106
/// Initialize [`Metadata`]
@@ -121,6 +132,7 @@ macro_rules! metadata {
121132
/// setup_panic!(Metadata::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
122133
/// .authors("My Company Support <[email protected]>")
123134
/// .homepage("support.mycompany.com")
135+
/// .support("- Open a support request by email to [email protected]")
124136
/// );
125137
/// ```
126138
#[macro_export]
@@ -206,8 +218,13 @@ fn write_msg<P: AsRef<Path>>(
206218
file_path: Option<P>,
207219
meta: &Metadata,
208220
) -> IoResult<()> {
209-
let (_version, name, authors, homepage) =
210-
(&meta.version, &meta.name, &meta.authors, &meta.homepage);
221+
let Metadata {
222+
name,
223+
authors,
224+
homepage,
225+
support,
226+
..
227+
} = meta;
211228

212229
writeln!(buffer, "Well, this is embarrassing.\n")?;
213230
writeln!(
@@ -233,6 +250,9 @@ fn write_msg<P: AsRef<Path>>(
233250
if let Some(authors) = authors {
234251
writeln!(buffer, "- Authors: {authors}")?;
235252
}
253+
if let Some(support) = support {
254+
writeln!(buffer, "\nTo submit the crash report:\n\n{support}")?;
255+
}
236256
writeln!(
237257
buffer,
238258
"\nWe take privacy seriously, and do not perform any \

tests/custom-panic/src/main.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use human_panic::setup_panic;
44
fn main() {
55
setup_panic!(metadata!()
66
.authors("My Company Support <[email protected]")
7-
.homepage("support.mycompany.com"));
7+
.homepage("www.mycompany.com")
8+
.support("- Open a support request by email to [email protected]"));
89

910
println!("A normal log message");
1011
panic!("OMG EVERYTHING IS ON FIRE!!!");

tests/custom-panic/tests/integration.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ fn release() {
1010
1111
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.
1212
13-
- Homepage: support.mycompany.com
13+
- Homepage: www.mycompany.com
1414
- Authors: My Company Support <[email protected]
1515
16+
To submit the crash report:
17+
18+
- Open a support request by email to [email protected]
19+
1620
We take privacy seriously, and do not perform any automated error collection. In order to improve the software, we rely on people to submit reports.
1721
1822
Thank you kindly!
@@ -26,7 +30,7 @@ fn debug() {
2630
snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("custom-panic-test"))
2731
.assert()
2832
.stderr_matches(snapbox::str![[r#"
29-
thread 'main' panicked at tests/custom-panic/src/main.rs:10:5:
33+
thread 'main' panicked at tests/custom-panic/src/main.rs:11:5:
3034
OMG EVERYTHING IS ON FIRE!!!
3135
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3236
"#]])

0 commit comments

Comments
 (0)