From 9a5c53b3ed11cc3f9d58417695d72c8c7df5a1c2 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 29 Oct 2019 15:46:11 -0700 Subject: [PATCH] Make wasi-common's `Error` messages prettier. (#156) Instead of returning the debug formatting, which includes the enum names, like `Io(...)`, just run the formatting function of the inner error objects, which is nicer for command-line use. --- src/error.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index 723e8a0d80..335f3d592f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -6,7 +6,7 @@ use std::convert::Infallible; use std::fmt; use std::num::TryFromIntError; -#[derive(Clone, Copy, Debug, Fail)] +#[derive(Clone, Copy, Debug, Fail, Eq, PartialEq)] #[repr(u16)] pub enum WasiError { ESUCCESS = host::__WASI_ESUCCESS, @@ -251,8 +251,13 @@ impl Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - _ => write!(f, "{:?}", self), + match self { + Self::Io(e) => e.fmt(f), + Self::Wasi(e) => e.fmt(f), + #[cfg(unix)] + Self::Nix(e) => e.fmt(f), + #[cfg(windows)] + Self::Win(e) => e.fmt(f), } } }