From 2b7160ebdf950ef872f785336fcfe17e0c4cb347 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 6 May 2022 08:39:14 +0300 Subject: refactor! split SubplotError::IoError into more specific errors Replace SubplotError::IoError with ::Spawn, ::WriteToChild, ::WaitForChild, ::ReadFile, ::CreateFile, ::Writefile. IoError was a catchall error and as such, so generic that it didn't help the user to figure out what actually is wrong. For example, there was no indication what operation was attempted or on what file. The new error variants are specific. Sponsored-by: author --- src/codegen.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/codegen.rs') diff --git a/src/codegen.rs b/src/codegen.rs index b940b4d..5c4255f 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -62,12 +62,15 @@ fn tera(tmplspec: &TemplateSpec, templatename: &str) -> Result Result Result<(), SubplotError> { - let mut f: File = File::create(filename)?; - f.write_all(content.as_bytes())?; + let mut f: File = File::create(filename) + .map_err(|err| SubplotError::CreateFile(filename.to_path_buf(), err))?; + f.write_all(content.as_bytes()) + .map_err(|err| SubplotError::WriteFile(filename.to_path_buf(), err))?; Ok(()) } -- cgit v1.2.1