Skip to content

Commit 688e544

Browse files
authored
Merge pull request #211 from epage/docs
docs: Make it easier to get started
2 parents 9aae18d + 1dbe491 commit 688e544

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

src/lib.rs

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,21 @@
11
//! Panic messages for humans
22
//!
3-
//! Handles panics by calling
4-
//! [`std::panic::set_hook`](https://doc.rust-lang.org/std/panic/fn.set_hook.html)
5-
//! to make errors nice for humans.
3+
//! Reduce the effort for users to report panics back to you
64
//!
7-
//! ## Why?
8-
//! When you're building a CLI, polish is super important. Even though Rust is
9-
//! pretty great at safety, it's not unheard of to access the wrong index in a
10-
//! vector or have an assert fail somewhere.
5+
//! You can still get the raw output by either:
6+
//! - Running a debug build
7+
//! - Setting `RUST_BACKTRACE=1`
118
//!
12-
//! When an error eventually occurs, you probably will want to know about it. So
13-
//! instead of just providing an error message on the command line, we can create a
14-
//! call to action for people to submit a report.
9+
//! ## Example
1510
//!
16-
//! This should empower people to engage in communication, lowering the chances
17-
//! people might get frustrated. And making it easier to figure out what might be
18-
//! causing bugs.
19-
//!
20-
//! ### Default Output
21-
//!
22-
//! ```txt
23-
//! thread 'main' panicked at 'oops', examples/main.rs:2:3
24-
//! note: Run with `RUST_BACKTRACE=1` for a backtrace.
11+
//! Add to your `fn main()`:
12+
//! ```rust
13+
//! human_panic::setup_panic!();
2514
//! ```
2615
//!
27-
//! ### Human-Panic Output
28-
//!
16+
//! When run locally in a release build:
2917
//! ```txt
30-
//! Well, this is embarrassing.
31-
//!
32-
//! human-panic had a problem and crashed. To help us diagnose the problem you can send us a crash report.
18+
//! my-program had a problem and crashed. To help us diagnose the problem you can send us a crash report.
3319
//!
3420
//! We have generated a report file at "/var/folders/zw/bpfvmq390lv2c6gn_6byyv0w0000gn/T/report-8351cad6-d2b5-4fe8-accd-1fcbf4538792.toml". Submit an issue or email with the subject of "human-panic Crash Report" and include the report as an attachment.
3521
//!
@@ -39,6 +25,13 @@
3925
//! 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.
4026
//!
4127
//! Thank you kindly!
28+
//! ```
29+
//!
30+
//! Traditional output:
31+
//! ```txt
32+
//! thread 'main' panicked at 'oops', examples/main.rs:2:3
33+
//! note: Run with `RUST_BACKTRACE=1` for a backtrace.
34+
//! ```
4235
4336
#![cfg_attr(docsrs, feature(doc_cfg))]
4437
#![warn(clippy::print_stderr)]
@@ -58,7 +51,16 @@ pub use panic::handle_dump;
5851
pub use panic::print_msg;
5952
pub use panic::setup_panic;
6053

61-
/// Initialize [`Metadata`]
54+
/// Collect Cargo [`Metadata`]
55+
///
56+
/// ## Example
57+
///
58+
/// ```rust
59+
/// use human_panic::metadata;
60+
///
61+
/// let metadata = metadata!()
62+
/// .support("- Open a support request by email to support@mycompany.com");
63+
/// ```
6264
#[macro_export]
6365
macro_rules! metadata {
6466
() => {{
@@ -69,25 +71,27 @@ macro_rules! metadata {
6971
}};
7072
}
7173

72-
/// `human-panic` initialisation macro
73-
///
74-
/// You can either call this macro with no arguments `setup_panic!()` or
75-
/// with a Metadata struct, if you don't want the error message to display
76-
/// the values used in your `Cargo.toml` file.
77-
///
78-
/// The Metadata struct can't implement `Default` because of orphan rules, which
79-
/// means you need to provide all fields for initialisation.
74+
/// Register `human-panic`
8075
///
8176
/// The macro should be called from within a function, for example as the first line of the
8277
/// `main()` function of the program.
8378
///
79+
/// ## Example
80+
///
81+
/// Default [`metadata!`]
82+
/// ```rust
83+
/// use human_panic::setup_panic;
84+
///
85+
/// setup_panic!();
8486
/// ```
87+
///
88+
/// Extend or override default [`metadata!`]
89+
/// ```rust
8590
/// use human_panic::setup_panic;
86-
/// use human_panic::Metadata;
91+
/// use human_panic::metadata;
8792
///
88-
/// setup_panic!(Metadata::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
93+
/// setup_panic!(metadata!()
8994
/// .authors("My Company Support <support@mycompany.com>")
90-
/// .homepage("support.mycompany.com")
9195
/// .support("- Open a support request by email to support@mycompany.com")
9296
/// );
9397
/// ```

0 commit comments

Comments
 (0)