Skip to content

Commit

Permalink
metadata: add repository
Browse files Browse the repository at this point in the history
Cargo guidelines are to not set a homepage if it isn't any different
than the repository URL. This causes the report to not have any link
back to file an issue. If the repository is available, print it as well.

Signed-off-by: Ben Boeckel <ben.boeckel@kitware.com>
  • Loading branch information
mathstuf committed Oct 15, 2018
1 parent 40b3fd7 commit f9ba6d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
//!
//! - Homepage: https://github.com/yoshuawuyts/human-panic
//! - Authors: Yoshua Wuyts <yoshuawuyts@gmail.com>
//! - Repository: https://github.com/yoshuawuyts/human-panic
//!
//! 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.
//!
Expand Down Expand Up @@ -70,6 +71,8 @@ pub struct Metadata {
pub authors: Cow<'static, str>,
/// The URL of the crate's website
pub homepage: Cow<'static, str>,
/// The URL of the crate's repository
pub repository: Cow<'static, str>,
}

/// `human-panic` initialisation macro
Expand All @@ -90,6 +93,7 @@ pub struct Metadata {
/// version: env!("CARGO_PKG_VERSION").into(),
/// authors: "My Company Support <support@mycompany.com".into(),
/// homepage: "support.mycompany.com".into(),
/// repository: "https://git.mycompany.com/repo.git".into(),
/// });
/// ```
#[macro_export]
Expand Down Expand Up @@ -127,6 +131,7 @@ macro_rules! setup_panic {
name: env!("CARGO_PKG_NAME").into(),
authors: env!("CARGO_PKG_AUTHORS").replace(":", ", ").into(),
homepage: env!("CARGO_PKG_HOMEPAGE").into(),
repository: option_env!("CARGO_PKG_REPOSITORY").unwrap_or("").into(),
};

panic::set_hook(Box::new(move |info: &PanicInfo| {
Expand All @@ -145,8 +150,8 @@ pub fn print_msg<P: AsRef<Path>>(
file_path: Option<P>,
meta: &Metadata,
) -> IoResult<()> {
let (_version, name, authors, homepage) =
(&meta.version, &meta.name, &meta.authors, &meta.homepage);
let (_version, name, authors, homepage, repository) =
(&meta.version, &meta.name, &meta.authors, &meta.homepage, &meta.repository);

let stderr = BufferWriter::stderr(ColorChoice::Auto);
let mut buffer = stderr.buffer();
Expand Down Expand Up @@ -177,6 +182,9 @@ pub fn print_msg<P: AsRef<Path>>(
if !authors.is_empty() {
writeln!(&mut buffer, "- Authors: {}", authors)?;
}
if !repository.is_empty() {
writeln!(&mut buffer, "- Repository: {}", repository)?;
}
writeln!(
&mut buffer,
"\nWe take privacy seriously, and do not perform any \
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 @@ -7,6 +7,7 @@ fn main() {
version: env!("CARGO_PKG_VERSION").into(),
authors: "My Company Support <support@mycompany.com".into(),
homepage: "support.mycompany.com".into(),
repository: "https://git.mycompany.com/repo.git".into(),
});

println!("A normal log message");
Expand Down

0 comments on commit f9ba6d8

Please sign in to comment.