Add annotations to loadJSArray
authorIustin Pop <iustin@google.com>
Thu, 27 May 2010 20:32:18 +0000 (22:32 +0200)
committerIustin Pop <iustin@google.com>
Thu, 27 May 2010 20:32:18 +0000 (22:32 +0200)
This allows, for example, the RAPI backend to detail which information
(instance or node data) fails to parse.

Ganeti/HTools/Rapi.hs
Ganeti/HTools/Utils.hs

index 42d4afe..183291c 100644 (file)
@@ -65,11 +65,13 @@ getInstances :: NameAssoc
              -> String
              -> Result [(String, Instance.Instance)]
 getInstances ktn body =
-    loadJSArray body >>= mapM (parseInstance ktn . fromJSObject)
+    loadJSArray "Parsing instance data" body >>=
+    mapM (parseInstance ktn . fromJSObject)
 
 -- | Parse a node list in JSON format.
 getNodes :: String -> Result [(String, Node.Node)]
-getNodes body = loadJSArray body >>= mapM (parseNode . fromJSObject)
+getNodes body = loadJSArray "Parsing node data" body >>=
+                mapM (parseNode . fromJSObject)
 
 -- | Construct an instance from a JSON object.
 parseInstance :: [(String, Ndx)]
index 736fcd8..cf69dae 100644 (file)
@@ -112,8 +112,11 @@ readEitherString v =
       _ -> fail "Wrong JSON type"
 
 -- | Converts a JSON message into an array of JSON objects.
-loadJSArray :: (Monad m) => String -> m [J.JSObject J.JSValue]
-loadJSArray = fromJResult . J.decodeStrict
+loadJSArray :: (Monad m)
+               => String -- ^ Operation description (for error reporting)
+               -> String -- ^ Input message
+               -> m [J.JSObject J.JSValue]
+loadJSArray s = annotateJResult s . J.decodeStrict
 
 -- | Reads a the value of a key in a JSON object.
 fromObj :: (J.JSON a, Monad m) => String -> [(String, J.JSValue)] -> m a