diff options
| author | Nathan | 2017-07-27 13:40:41 -0400 | 
|---|---|---|
| committer | Nathan | 2017-07-27 13:40:41 -0400 | 
| commit | e8ee8223a87cb8b730905808162435e5b716b59b (patch) | |
| tree | 519a82772fe0c1841c2f5c22e739c9dff5675c4d /src/utils.rs | |
| parent | a03435811860addf4cdb498caf5a15887be1db05 (diff) | |
| download | podcast-e8ee8223a87cb8b730905808162435e5b716b59b.tar.bz2 | |
Better error handling
Diffstat (limited to 'src/utils.rs')
| -rw-r--r-- | src/utils.rs | 19 | 
1 files changed, 8 insertions, 11 deletions
| diff --git a/src/utils.rs b/src/utils.rs index 5444cb1..113517e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,11 +1,9 @@  use std::collections::HashSet;  use std::env; +use std::fs::DirBuilder;  use std::fs;  use std::num::ParseIntError;  use std::path::PathBuf; -use std::fs::DirBuilder; -use std::io; -  pub fn trim_extension(filename: &str) -> String {      let name = String::from(filename); @@ -28,16 +26,15 @@ pub fn find_extension(input: &str) -> Option<&str> {      }  } -pub fn create_directories() -> io::Result<()> { +pub fn create_directories() -> Result<(), String> {      let mut path = get_podcast_dir();      path.push(".rss");      if let Err(err) = DirBuilder::new().recursive(true).create(&path) { -        eprintln!( -                    "Couldn't create directory: {}\nReason: {}", -                    path.to_str().unwrap(), -                    err -                    ); -        return Err(err) +        return Err(format!( +            "Couldn't create directory: {}\nReason: {}", +            path.to_str().unwrap(), +            err +        ));      }      Ok(())  } @@ -61,7 +58,7 @@ pub fn already_downloaded(dir: &str) -> HashSet<String> {                          println!(                              "OsString: {:?} couldn't be converted to String",                              entry.file_name() -                            ); +                        );                      }                  }              } | 
