Revision 50d26669

b/Ganeti/HTools/Utils.hs
97 97
fromJResult (J.Error x) = fail x
98 98
fromJResult (J.Ok x) = return x
99 99

  
100
annotateJResult :: Monad m => String -> J.Result a -> m a
101
annotateJResult s (J.Error x) = fail (s ++ ": " ++ x)
102
annotateJResult _ (J.Ok x) = return x
103

  
100 104
-- | Tries to read a string from a JSON value.
101 105
--
102 106
-- In case the value was not a string, we fail the read (in the
......
116 120
fromObj k o =
117 121
    case lookup k o of
118 122
      Nothing -> fail $ printf "key '%s' not found in %s" k (show o)
119
      Just val -> fromJResult $ J.readJSON val
123
      Just val -> annotateJResult (printf "key '%s', value '%s'" k (show val))
124
                  (J.readJSON val)
120 125

  
121 126
-- | Annotate a Result with an ownership information
122 127
annotateResult :: String -> Result a -> Result a
......
127 132
-- than fromObj
128 133
tryFromObj :: (J.JSON a) =>
129 134
              String -> [(String, J.JSValue)] -> String -> Result a
130
tryFromObj t o k = annotateResult (t ++ " key '" ++ k ++ "'") (fromObj k o)
135
tryFromObj t o k = annotateResult t (fromObj k o)
131 136

  
132 137
-- | Small wrapper over readJSON.
133 138
fromJVal :: (Monad m, J.JSON a) => J.JSValue -> m a

Also available in: Unified diff