aboutsummaryrefslogtreecommitdiff
path: root/Messages/JSON.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2018-02-19 14:59:30 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2018-02-19 15:07:00 -0400
commit7f49e1b922d83fa6548c4c9357591b661cbf1c46 (patch)
treec20c1bbd4c88d8cf7c404e4fd7fd4cd2fa8883ae /Messages/JSON.hs
parentec1e50642b62fa3dcf5a2c9f7fd582e403c17627 (diff)
always include error-messages field when --json-error-messages
Always include error-messages field, even if empty, to make the json be self-documenting. This was a design requirement for --json-error-messages. This commit was supported by the NSF-funded DataLad project.
Diffstat (limited to 'Messages/JSON.hs')
-rw-r--r--Messages/JSON.hs15
1 files changed, 14 insertions, 1 deletions
diff --git a/Messages/JSON.hs b/Messages/JSON.hs
index 9b9ca67cf..1fe989f7f 100644
--- a/Messages/JSON.hs
+++ b/Messages/JSON.hs
@@ -1,6 +1,6 @@
{- git-annex command-line JSON output and input
-
- - Copyright 2011-2016 Joey Hess <id@joeyh.name>
+ - Copyright 2011-2018 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -14,6 +14,7 @@ module Messages.JSON (
none,
start,
end,
+ finalize,
note,
info,
add,
@@ -37,6 +38,7 @@ import Data.Maybe
import Data.Monoid
import Prelude
+import Types.Messages
import Key
import Utility.Metered
import Utility.Percentage
@@ -74,6 +76,17 @@ end :: Bool -> JSONBuilder
end b (Just (o, _)) = Just (HM.insert "success" (toJSON b) o, True)
end _ Nothing = Nothing
+finalize :: JSONOptions -> Object -> Object
+finalize jsonoptions o
+ -- Always include error-messages field, even if empty,
+ -- to make the json be self-documenting.
+ | jsonErrorMessages jsonoptions =
+ HM.insertWith combinearray "error-messages" (Array mempty) o
+ | otherwise = o
+ where
+ combinearray (Array new) (Array old) = Array (old <> new)
+ combinearray new _old = new
+
note :: String -> JSONBuilder
note _ Nothing = Nothing
note s (Just (o, e)) = Just (HM.insertWith combinelines "note" (toJSON s) o, e)