From d2fdd7b76124fd08ee0c783d6aeb8dcd58b4e959 Mon Sep 17 00:00:00 2001 From: sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> Date: Wed, 17 Feb 2021 18:24:35 +0100 Subject: pkgs/profpatsch/nman: print io::Error for NmanError::IO We reuse std::io::Error's Display trait to print precisely the error that occurred to the user as well. This will probably help a lot if an IO error should ever occurr, as they will only ever occurr in very weird situations (mktemp(3) failed or share/man is not a readable directory). --- pkgs/profpatsch/nman/nman.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'pkgs/profpatsch/nman') diff --git a/pkgs/profpatsch/nman/nman.rs b/pkgs/profpatsch/nman/nman.rs index 448314f3..016b97b1 100644 --- a/pkgs/profpatsch/nman/nman.rs +++ b/pkgs/profpatsch/nman/nman.rs @@ -18,7 +18,7 @@ use temp::TempDir; /// exit code for the occurred error (not that it /// really matters for an interactive tool). enum NmanError<'a> { - IO, + IO(std::io::Error), Instantiate(&'a str, Vec), Build(OsString, Vec), Man, @@ -46,8 +46,7 @@ impl NmanError<'_> { fn msg(&self) -> String { match self { - // TODO(sterni): make more descriptive - NmanError::IO => String::from("unexpected IO error"), + NmanError::IO(err) => format!("unexpected IO error occurred: {}", err), NmanError::Instantiate(attr, stderr) => format!("could not instantiate \"{}\". nix-instantiate reported:\n{}", attr, std::str::from_utf8(&stderr).unwrap_or("")), @@ -196,7 +195,7 @@ fn build_man_page<'a>(drv: DrvWithOutput, section: Option<&str>, page: &str, tem Some(s) => vec!(OsString::from(format!("man{}", s))), None => { std::fs::read_dir(path.as_path()) - .map_err(|_| NmanError::IO)? + .map_err(NmanError::IO)? .filter_map(|entry| entry.ok()) .map(|entry| entry.file_name()) .collect() @@ -249,7 +248,7 @@ fn build_man_page<'a>(drv: DrvWithOutput, section: Option<&str>, page: &str, tem /// (any man implementation that implements `-l` should /// for that matter). fn open_man_page<'a>(attr: &'a str, section: Option<&'a str>, page: &'a str) -> Result<(), NmanError<'a>> { - let tmpdir = TempDir::new("nman").map_err(|_| NmanError::IO)?; + let tmpdir = TempDir::new("nman").map_err(NmanError::IO)?; // TODO(sterni): allow selecting other base package sets, // like , /home/lukas/src/nix/nixpkgs, … let expr = format!("with (import {{}}); builtins.map (o: {}.\"${{o}}\") {}.outputs", attr, attr); -- cgit 1.4.1