From 2befdc14ad9f965499ee8719b9247d807aaa5dbe Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 7 Jan 2011 14:26:48 +0100 Subject: [PATCH] JSON: improve error reporting Currently, we list the entire object in error messages. But for large objects (e.g. an IAllocator message), this makes the output unreadable, as the elements are containers themselves. To simplify the reporting, we only list the keys, as this is more relevent than the values. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Balazs Lecz <leczb@google.com> --- Ganeti/HTools/Utils.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Ganeti/HTools/Utils.hs b/Ganeti/HTools/Utils.hs index 1e58bc33f..5611dbc9c 100644 --- a/Ganeti/HTools/Utils.hs +++ b/Ganeti/HTools/Utils.hs @@ -130,7 +130,8 @@ loadJSArray s = fromJResult s . J.decodeStrict fromObj :: (J.JSON a, Monad m) => [(String, J.JSValue)] -> String -> m a fromObj o k = case lookup k o of - Nothing -> fail $ printf "key '%s' not found in %s" k (show o) + Nothing -> fail $ printf "key '%s' not found, object contains only %s" + k (show (map fst o)) Just val -> fromKeyValue k val -- | Reads the value of an optional key in a JSON object. -- GitLab