Revision a64cc96b src/Ganeti/Query/Common.hs

b/src/Ganeti/Query/Common.hs
27 27
  ( rsNoData
28 28
  , rsUnavail
29 29
  , rsNormal
30
  , rsMaybe
30
  , rsMaybeNoData
31
  , rsMaybeUnavail
31 32
  , rsUnknown
32 33
  , missingRuntime
33 34
  , rpcErrorToStatus
......
79 80
-- missing, in which case we return no data). Note that there's some
80 81
-- ambiguity here: in some cases, we mean 'RSNoData', but in other
81 82
-- 'RSUnavail'; this is easy to solve in simple cases, but not in
82
-- nested dicts.
83
rsMaybe :: (JSON a) => Maybe a -> ResultEntry
84
rsMaybe = maybe rsNoData rsNormal
83
-- nested dicts. If you want to return 'RSUnavail' in case of 'Nothing'
84
-- use the function 'rsMaybeUnavail'.
85
rsMaybeNoData :: (JSON a) => Maybe a -> ResultEntry
86
rsMaybeNoData = maybe rsNoData rsNormal
87

  
88
-- | Helper to declare a result from a 'Maybe'. This version returns
89
-- a 'RSUnavail' in case of 'Nothing'. It should be used for optional
90
-- fields that are not set. For cases where 'Nothing' means that there
91
-- was an error, consider using 'rsMaybe' instead.
92
rsMaybeUnavail :: (JSON a) => Maybe a -> ResultEntry
93
rsMaybeUnavail = maybe rsUnavail rsNormal
85 94

  
86 95
-- | Helper for unknown field result.
87 96
rsUnknown :: ResultEntry
......
135 144
-- levels of maybe: the top level dict might be missing, or one key in
136 145
-- the dictionary might be.
137 146
dictFieldGetter :: (DictObject a) => String -> Maybe a -> ResultEntry
138
dictFieldGetter k = maybe rsNoData (rsMaybe . lookup k . toDict)
147
dictFieldGetter k = maybe rsNoData (rsMaybeNoData . lookup k . toDict)
139 148

  
140 149
-- | Build an optimised lookup map from a Python _PARAMETER_TYPES
141 150
-- association list.

Also available in: Unified diff