diff options
Diffstat (limited to 'src')
-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")); } |