Skip to content

Commit

Permalink
refactor: add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelvanderwaal committed Jun 16, 2022
1 parent ad37fdf commit c68f5b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wtf-is"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
license = "MIT"
description = "I was tired of looking up Metaplex program errors."
Expand Down
20 changes: 17 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,32 @@ pub struct FoundError {
}

fn main() {
let error_code = args().nth(1).unwrap();
let error_code = match args().nth(1) {
Some(code) => code,
None => {
println!("Usage: {} <error code>", args().next().unwrap());
std::process::exit(1);
}
};

let parsed_error_code = if error_code.contains("0x") {
error_code.replace("0x", "")
} else {
format!("{:X}", error_code.parse::<i64>().unwrap())
let parsed_code = match error_code.parse::<i64>() {
Ok(code) => code,
Err(_) => {
println!("Error: {error_code} is not a valid error code");
std::process::exit(1);
}
};

format!("{:X}", parsed_code)
};

let errors = find_errors(&parsed_error_code);

if errors.is_empty() {
println!("No errors for found code: {parsed_error_code}");
println!("No errors for found code: 0x{parsed_error_code}");
std::process::exit(1);
}

Expand Down

0 comments on commit c68f5b8

Please sign in to comment.