-
-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add debug info under panic with debug build (#4940)
* chore: add debug info under panic with debug build * fix * fix
- Loading branch information
Showing
4 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::fmt::Display; | ||
use std::sync::Mutex; | ||
|
||
/// Debug info used when programs panics | ||
/// Only works with #[cfg(debug_assertions)] | ||
pub struct DebugInfo { | ||
/// The base directory. See [options.context](https://webpack.js.org/configuration/entry-context/#context) | ||
pub(crate) context: Option<String>, | ||
} | ||
|
||
impl DebugInfo { | ||
const fn new() -> Self { | ||
Self { context: None } | ||
} | ||
|
||
pub(crate) fn with_context(&mut self, context: String) -> &mut Self { | ||
self.context = Some(context); | ||
self | ||
} | ||
} | ||
|
||
macro_rules! write_debug_info { | ||
($f:ident,$tt:tt,$expr:expr) => { | ||
let tt = $tt.to_string(); | ||
if let Some(e) = &$expr { | ||
let e = format!("\u{001b}[1m\u{001b}[33m{tt}\u{001b}[0m: {e}"); | ||
writeln!($f, "{}", e)?; | ||
} else { | ||
let e = format!("\u{001b}[1m\u{001b}[33m{tt}\u{001b}[0m: <empty>"); | ||
writeln!($f, "{}", e)?; | ||
} | ||
}; | ||
} | ||
|
||
impl Display for DebugInfo { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
writeln!(f, "DebugInfo:\n")?; | ||
write_debug_info!(f, "context", &self.context); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
pub static DEBUG_INFO: Mutex<DebugInfo> = Mutex::new(DebugInfo::new()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters