diff options
author | sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> | 2021-02-17 18:24:35 +0100 |
---|---|---|
committer | sternenseemann <sternenseemann@systemli.org> | 2021-02-25 19:52:33 +0100 |
commit | d2fdd7b76124fd08ee0c783d6aeb8dcd58b4e959 (patch) | |
tree | bae925ecae20dd080af25af7e70ec23a709388f4 /pkgs/profpatsch/nman | |
parent | 0d28298f72fc8d9084a249c3c62f93a78167fc3a (diff) |
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).
Diffstat (limited to 'pkgs/profpatsch/nman')
-rw-r--r-- | pkgs/profpatsch/nman/nman.rs | 9 |
1 files changed, 4 insertions, 5 deletions
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<u8>), Build(OsString, Vec<u8>), 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("<invalid utf-8>")), @@ -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 <vuizvui>, /home/lukas/src/nix/nixpkgs, … let expr = format!("with (import <nixpkgs> {{}}); builtins.map (o: {}.\"${{o}}\") {}.outputs", attr, attr); |