X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fhtsn.git;a=blobdiff_plain;f=src%2FMain.hs;fp=src%2FMain.hs;h=de0e28e53ea9dfa48fa4d8cb202216b1e9b67788;hp=aebf5c503aa53f413100243900aee69b939e3c99;hb=c4698230179be17f66dc17339cef379733b89fd1;hpb=1d58dc651f06286ee42d17341fea107f8737f709 diff --git a/src/Main.hs b/src/Main.hs index aebf5c5..de0e28e 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -5,6 +5,7 @@ module Main where -- System imports. +import Control.Applicative ( (<$>) ) import Control.Concurrent ( threadDelay ) import Control.Exception ( bracket, throw ) import Control.Monad ( when ) @@ -71,12 +72,17 @@ recv_line h = do -- This can fail, but we don't purposefully throw any exceptions. If -- something goes wrong, we would rather log it and keep going. -- +-- And in fact the only \"error\" that can occur is from +-- 'parse_xmlfid' if TSN sends us a non-integer XML File ID. But +-- this is expected from time to time, and is merely unsupported. So +-- we report any failures as info instead of as errors. +-- save_document :: Configuration -> String -- ^ String representation of an XML document -> IO () save_document cfg doc = case either_path of - Left err -> report_error err + Left err -> report_info err -- Can only be non-integer XML File ID Right path -> do already_exists <- doesFileExist path when already_exists $ do @@ -85,10 +91,10 @@ save_document cfg doc = writeFile path doc report_info $ "Wrote file: " ++ path ++ "." where - -- All the fmaps are because we're working inside a Maybe. - xmlfid = fmap show (parse_xmlfid doc) - filename = fmap (++ ".xml") xmlfid - either_path = fmap ((output_directory cfg) ) filename + -- All the <$> are because we're working inside an Either. + xmlfid = show <$> (parse_xmlfid doc) + filename = (++ ".xml") <$> xmlfid + either_path = ((output_directory cfg) ) <$> filename -- | Loop forever, writing the @buffer@ to file whenever a