Skip to content

Commit 3286550

Browse files
fix: don't print crash report with git panic handler (#760)
1 parent e9b61d2 commit 3286550

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

crates/rover-client/src/shared/git_context.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,7 @@ impl GitContext {
103103
// will return None
104104
fn sanitize_remote_url(remote_url: &str) -> Option<String> {
105105
// try to parse url into git info
106-
107-
// GitUrl::parse can panic, so we attempt to catch it and
108-
// just return None if the parsing fails.
109-
110-
let parsed_remote_url = panic::catch_unwind(|| GitUrl::parse(remote_url).ok())
111-
.ok()
112-
.flatten();
106+
let parsed_remote_url = parse_git_remote(remote_url);
113107

114108
if let Some(mut parsed_remote_url) = parsed_remote_url {
115109
// return None for any remote that is not a supported host
@@ -142,6 +136,26 @@ impl GitContext {
142136
}
143137
}
144138

139+
// GitUrl::parse can panic, so we attempt to catch it and
140+
// just return None if the parsing fails.
141+
fn parse_git_remote(remote_url: &str) -> Option<GitUrl> {
142+
// we make sure to store the original panic handler
143+
let original_panic_handler = panic::take_hook();
144+
145+
// set a new hook to suppress the panic message
146+
panic::set_hook(Box::new(|_| {}));
147+
148+
// parse the git remote
149+
let parsed_remote_url = panic::catch_unwind(|| GitUrl::parse(remote_url).ok())
150+
.ok()
151+
.flatten();
152+
153+
// and restore the original panic handler
154+
panic::set_hook(original_panic_handler);
155+
156+
parsed_remote_url
157+
}
158+
145159
#[cfg(test)]
146160
mod tests {
147161
use super::*;

0 commit comments

Comments
 (0)