The dotfiles manager.
refactor: better error handling
1 file changed, +7 -4
+7-4src/main.rs
| @@ -355,10 +355,13 @@ enum FlexEntry { | ||
| 355 | 355 | |
| 356 | 356 | fn cmd_flex(args: FlexArgs) -> Result<()> { |
| 357 | 357 | let url = args.url.as_deref().unwrap_or(DEFAULT_FLEX_URL); |
| 358 | - let yaml = fetch_text(url).or_else(|_| { | |
| 359 | - // Fallback to local flex.yml if remote fails | |
| 360 | - fs::read_to_string("flex.yml").context("Failed to fetch and failed to read local flex.yml") | |
| 361 | - })?; | |
| 358 | + let yaml = match fetch_text(url) { | |
| 359 | + Ok(text) => text, | |
| 360 | + Err(_) => { | |
| 361 | + eprintln!("\x1b[31mFailed to fetch the flex file. Please enure you have internet connection.\x1b[0m"); | |
| 362 | + std::process::exit(1); | |
| 363 | + } | |
| 364 | + }; | |
| 362 | 365 | |
| 363 | 366 | let map: HashMap<String, FlexEntry> = serde_yaml::from_str(&yaml) |
| 364 | 367 | .context("Parsing YAML for flex")?; |