Skip to content

Commit 61258dd

Browse files
committed
process-logs: avoid holding all of the log in memory before processing it
1 parent 95ef932 commit 61258dd

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

dev-tools/process-logs/Main.hs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,15 @@ import Kore.JsonRpc.Types.ContextLog
3737
main :: IO ()
3838
main = do
3939
Options{cmd, input, output} <- execParser parse
40-
(errors, inputJson) <-
41-
partitionEithers
42-
. map JSON.eitherDecode
40+
inputData <-
41+
map JSON.eitherDecode
4342
. BS.lines
4443
<$> maybe BS.getContents BS.readFile input
45-
unless (null errors) $ do
46-
putStrLn "JSON parse errors in log file:"
47-
mapM_ putStrLn errors
48-
exitWith (ExitFailure 1)
4944
let writeOut = maybe BS.putStrLn BS.writeFile output . BS.unlines
50-
writeOut $ process cmd inputJson
45+
writeOut $ process cmd $ stopOnErrors inputData
46+
where
47+
stopOnErrors :: [Either String LogLine] -> [LogLine]
48+
stopOnErrors = map (either (error . ("JSON parse error: " <>)) id)
5149

5250
data Options = Options
5351
{ cmd :: Command

0 commit comments

Comments
 (0)