diff options
author | Qrius <[email protected]> | 2024-09-26 00:11:05 +0200 |
---|---|---|
committer | Qrius <[email protected]> | 2024-09-26 00:11:05 +0200 |
commit | e489f7d9f8b799ee1605b4d5cb65fe7adf24ea22 (patch) | |
tree | 8c579991dc45db912eb1377a2175e5b7659f647b | |
parent | c52e9eafe7c7858e240c3bf5c8c87563e55b0837 (diff) | |
download | skaldpress-e489f7d9f8b799ee1605b4d5cb65fe7adf24ea22.tar.gz skaldpress-e489f7d9f8b799ee1605b4d5cb65fe7adf24ea22.zip |
Add more error handling
-rw-r--r-- | src/skaldpress/main.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/skaldpress/main.rs b/src/skaldpress/main.rs index 265f7fc..79ea7ab 100644 --- a/src/skaldpress/main.rs +++ b/src/skaldpress/main.rs @@ -10,7 +10,9 @@ const CONTENT_DIR: &str = "content/"; const BUILD_DIR: &str = "build/"; fn compile_file(file_path: &Path) -> Result<String, SkaldpressError> { - let extension = file_path.extension().expect("SP14"); + let extension = file_path + .extension() + .ok_or(SkaldpressError::PathOperationError(7, None))?; let file_content = fs::read_to_string(file_path).map_err(|e| { SkaldpressError::FileReadError( @@ -74,7 +76,7 @@ fn compile_file_and_write(source_file_path: &Path) -> Result<(), Box<dyn std::er fn compile_files_in_directory(directory: &Path) -> Result<(), SkaldpressError> { for entry in fs::read_dir(directory).map_err(|e| { SkaldpressError::DirectoryReadError( - 6, + 8, e, directory.to_str().unwrap_or("unknown dir").to_string(), ) @@ -87,7 +89,13 @@ fn compile_files_in_directory(directory: &Path) -> Result<(), SkaldpressError> { } }; let path = entry.path(); - let metadata = fs::metadata(&path).expect("SP6"); + let metadata = match fs::metadata(&path) { + Ok(metadata) => metadata, + Err(e) => { + println!("\x1b[31mError getting file metadata {:#?}\x1b[0m", e); + continue; + } + }; if metadata.is_file() { println!("Compiling {:#?}", path.as_path()); @@ -118,5 +126,5 @@ fn main() { let _ = compile_files_in_directory(Path::new(CONTENT_DIR)); // Just for testing - //compile_file_and_write(Path::new("content/test.html")).expect("AYYYYO"); + //compile_file_and_write(Path::new("content/test.html")); } |