remove some comments and add some horrible error handling

This commit is contained in:
SadlyNotSappho 2023-08-29 14:20:11 -07:00
parent 1367f2d684
commit d8d3311d25
2 changed files with 24 additions and 11 deletions

View File

@ -17,12 +17,9 @@ pub async fn download_image(cache_path: &String, image_url: String, file_name: S
process::exit(1); process::exit(1);
} }
}; };
// println!("{image:?}");
// println!("{}", yansi::Color::Magenta.paint(filename.clone())); // println!("{replaced}/{file_name}");
// println!("{}", yansi::Color::Magenta.paint(filepath.clone()));
println!("{replaced}/{file_name}");
let wrote = fs::write(format!("{replaced}/{file_name}"), image); let wrote = fs::write(format!("{replaced}/{file_name}"), image);
if let Err(why) = wrote { if let Err(why) = wrote {
eprintln!("cache::download_image: Couldn't save the image to `{replaced}/{file_name}`: {why:?}"); eprintln!("cache::download_image: Couldn't save the image to `{replaced}/{file_name}`: {why:?}");

View File

@ -1,17 +1,33 @@
pub mod cache; pub mod cache;
use std::{fs, path::Path}; use std::{fs, path::Path, process};
use scraper::{Html, Selector}; use scraper::{Html, Selector};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub fn get_home() -> String { pub fn get_home() -> String {
match std::env::consts::OS { match std::env::consts::OS {
"linux" => std::env::var("HOME").expect("how is there not a $HOME"), "linux" => match std::env::var("HOME") {
"windows" => std::env::var("userprofile").expect("yell at me if this doesn't work please"), Ok(var) => var,
_ => std::env::var("HOME").expect( Err(why) => {
"if this doesn't work, you're probably on macos, which i literally cannot test on", eprintln!("lib::get_home: Couldn't get $HOME on Linux: {why:?}");
), process::exit(1);
}
},
"windows" => match std::env::var("userprofile") {
Ok(var) => var,
Err(why) => {
eprintln!("lib::get_home: Couldn't get $userprofile on Windows: {why:?}");
process::exit(1)
}
},
_ => match std::env::var("HOME") {
Ok(var) => var,
Err(why) => {
eprintln!("lib::get_home: Couldn't get $HOME on other OS: {why:?}");
process::exit(1)
}
}
} }
} }