diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2023-06-20 19:16:18 +0200 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2023-07-29 11:42:50 +0200 |
| commit | 0e729404da1e741e26a398192fcd1614514117cf (patch) | |
| tree | 5a67cfd4d6629dbfc922321328f6d2f1a8ed8f1f /library/core/src | |
| parent | 04411507bef1d2db441acdc1d89268f0cbaaccbc (diff) | |
| download | rust-0e729404da1e741e26a398192fcd1614514117cf.tar.gz rust-0e729404da1e741e26a398192fcd1614514117cf.zip | |
Change default panic handler message format.
Diffstat (limited to 'library/core/src')
| -rw-r--r-- | library/core/src/error.md | 6 | ||||
| -rw-r--r-- | library/core/src/panic/panic_info.rs | 10 |
2 files changed, 10 insertions, 6 deletions
diff --git a/library/core/src/error.md b/library/core/src/error.md index 78808d489b2..7771b8adc92 100644 --- a/library/core/src/error.md +++ b/library/core/src/error.md @@ -93,7 +93,8 @@ information that is already communicated by the source error being unwrapped: ```text -thread 'main' panicked at 'env variable `IMPORTANT_PATH` is not set: NotPresent', src/main.rs:4:6 +thread 'main' panicked at src/main.rs:4:6: +env variable `IMPORTANT_PATH` is not set: NotPresent ``` In this example we end up mentioning that an env variable is not set, @@ -109,7 +110,8 @@ prevent the source error, we end up introducing new information that is independent from our source error. ```text -thread 'main' panicked at 'env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`: NotPresent', src/main.rs:4:6 +thread 'main' panicked at src/main.rs:4:6: +env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`: NotPresent ``` In this example we are communicating not only the name of the diff --git a/library/core/src/panic/panic_info.rs b/library/core/src/panic/panic_info.rs index 5576adde84b..c7f04f11ef6 100644 --- a/library/core/src/panic/panic_info.rs +++ b/library/core/src/panic/panic_info.rs @@ -147,16 +147,18 @@ impl<'a> PanicInfo<'a> { impl fmt::Display for PanicInfo<'_> { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.write_str("panicked at ")?; + self.location.fmt(formatter)?; if let Some(message) = self.message { - write!(formatter, "'{}', ", message)? + formatter.write_str(":\n")?; + formatter.write_fmt(*message)?; } else if let Some(payload) = self.payload.downcast_ref::<&'static str>() { - write!(formatter, "'{}', ", payload)? + formatter.write_str(":\n")?; + formatter.write_str(payload)?; } // NOTE: we cannot use downcast_ref::<String>() here // since String is not available in core! // The payload is a String when `std::panic!` is called with multiple arguments, // but in that case the message is also available. - - self.location.fmt(formatter) + Ok(()) } } |
