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: Allow aderyn to exit without crashing if update-check fails #753

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 11 additions & 9 deletions aderyn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,23 @@ fn right_pad(s: &str, by: usize) -> String {

pub static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));

pub fn aderyn_is_currently_running_newest_version() -> Result<bool, reqwest::Error> {
pub fn aderyn_is_currently_running_newest_version() -> Option<bool> {
let client = reqwest::blocking::Client::builder()
.user_agent(APP_USER_AGENT)
.build()?;
.build()
.expect("client is unable to initialize");

let latest_version_checker = client
.get("https://api.github.com/repos/Cyfrin/aderyn/releases/latest")
.send()?;
.send()
.ok()?;

let data = latest_version_checker.json::<Value>()?;
let newest =
Version::parse(data["tag_name"].as_str().unwrap().replace('v', "").as_str()).unwrap();
let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
let data = latest_version_checker.json::<Value>().ok()?;
let version_string = data["tag_name"].as_str()?;
let newest = Version::parse(version_string.replace('v', "").as_str()).ok()?;
let current = Version::parse(env!("CARGO_PKG_VERSION")).expect("Pkg version not available");

Ok(current >= newest)
Some(current >= newest)
}

#[cfg(test)]
Expand All @@ -111,6 +113,6 @@ mod latest_version_checker_tests {

#[test]
fn can_get_latest_version_from_crate_registry() {
assert!(aderyn_is_currently_running_newest_version().is_ok())
assert!(aderyn_is_currently_running_newest_version().is_some())
}
}
2 changes: 1 addition & 1 deletion aderyn/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn main() {

// Check for updates
if !cmd_args.skip_update_check {
if let Ok(yes) = aderyn_is_currently_running_newest_version() {
if let Some(yes) = aderyn_is_currently_running_newest_version() {
if !yes {
println!();
println!("NEW VERSION OF ADERYN AVAILABLE! Please run `cyfrinup` to upgrade.");
Expand Down
Loading