Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't print crash report with git panic handler #760

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions crates/rover-client/src/shared/git_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,7 @@ impl GitContext {
// will return None
fn sanitize_remote_url(remote_url: &str) -> Option<String> {
// try to parse url into git info

// GitUrl::parse can panic, so we attempt to catch it and
// just return None if the parsing fails.

let parsed_remote_url = panic::catch_unwind(|| GitUrl::parse(remote_url).ok())
.ok()
.flatten();
let parsed_remote_url = parse_git_remote(remote_url);

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

// GitUrl::parse can panic, so we attempt to catch it and
// just return None if the parsing fails.
fn parse_git_remote(remote_url: &str) -> Option<GitUrl> {
// we make sure to store the original panic handler
let original_panic_handler = panic::take_hook();

// set a new hook to suppress the panic message
panic::set_hook(Box::new(|_| {}));

// parse the git remote
let parsed_remote_url = panic::catch_unwind(|| GitUrl::parse(remote_url).ok())
.ok()
.flatten();

// and restore the original panic handler
panic::set_hook(original_panic_handler);

parsed_remote_url
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down