Skip to content

Commit

Permalink
Gt/Helpers.hs: now print full text of bad json object
Browse files Browse the repository at this point in the history
Signed-off-by: Sergei Trofimovich <siarheit@google.com>
  • Loading branch information
trofi committed Apr 9, 2015
1 parent 3681dfa commit 2568ba4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Gt/Core.hs
Expand Up @@ -22,8 +22,8 @@ do_trans_each_word :: IO String
do_trans_each_word = error "Gt.Core.do_trans_each_word: unimplemented"

jresp_to_resp :: String -> Resp
jresp_to_resp jobj = foldr fill_resp br obj_list
where obj_list = fromJSObject $ from_ok (decode jobj :: Result (JSObject JSValue))
jresp_to_resp unparsed_json = foldr fill_resp br obj_list
where obj_list = fromJSObject $ from_ok unparsed_json (decode unparsed_json :: Result (JSObject JSValue))
br = blank_resp

fill_resp :: (String, JSValue) -> Resp -> Resp
Expand Down
11 changes: 7 additions & 4 deletions Gt/Helpers.hs
Expand Up @@ -37,10 +37,13 @@ shift_lines n = unlines . map (replicate (n*4) ' ' ++) . lines


-- JSON deconstruct helpers
from_ok :: Result a -> a
from_ok (Ok x) = x
from_ok (Error e) = error $ "Gt.Helpers.from_ok: " ++ show e

from_ok :: String -> Result a -> a
from_ok _raw_data (Ok x) = x
from_ok raw_data (Error e) = error $ unlines [ "Gt.Helpers.from_ok:"
, show e
, "on input:"
, show raw_data
]
jarr_to_list :: JSValue -> [JSValue]
jarr_to_list (JSArray jarr) = jarr
jarr_to_list _ = []
Expand Down

0 comments on commit 2568ba4

Please sign in to comment.