Last active
January 21, 2016 21:46
-
-
Save maddie927/83c66a1e76d1b937aba7 to your computer and use it in GitHub Desktop.
build error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Prelude (Unit, bind, pure, show, unit, ($), (<$>), (<>)) | |
import Control.Monad.Eff (Eff) | |
import Control.Monad.Eff.Console (CONSOLE) | |
import Control.Monad.Eff.Exception (EXCEPTION) | |
import Data.Either (Either(Left, Right)) | |
import Data.Foreign (F) | |
import Data.Foreign.Class (class IsForeign, readJSON, readProp) | |
import Data.String (joinWith, split) | |
import Node.Encoding (Encoding(UTF8)) | |
import Node.Process (stdin, stdout) | |
import Node.ReadLine (InterfaceOptions(Input), createInterface, setLineHandler) | |
import Node.Stream (Duplex, pipe, writeString) | |
foreign import data GZIP :: ! | |
foreign import gunzip :: forall eff. Eff (gzip :: GZIP | eff) (Duplex (gzip :: GZIP | eff)) | |
newtype CloudFlareLog = CloudFlareLog { rayId :: String } | |
instance cloudFlareLogIsForeign :: IsForeign CloudFlareLog where | |
read json = do | |
rayId <- readProp "rayId" json | |
pure $ CloudFlareLog { rayId: rayId } | |
parseLog :: String -> F CloudFlareLog | |
parseLog log = readJSON log | |
handleErrors :: F String -> String | |
handleErrors (Left err) = "-- failed to parse: " <> show err | |
handleErrors (Right result) = result | |
getRayId :: CloudFlareLog -> String | |
getRayId (CloudFlareLog log) = log.rayId | |
main :: forall e. Eff (gzip :: GZIP, console :: CONSOLE, err :: EXCEPTION | e) Unit | |
main = do | |
unzip <- gunzip | |
pipe stdin unzip | |
readline <- createInterface (Input { input: unzip }) | |
setLineHandler readline handleJson | |
pure unit | |
where | |
handleJson :: forall eff. String -> Eff (gzip :: GZIP, console :: CONSOLE, err :: EXCEPTION | eff) Unit | |
handleJson str = do | |
writeStdoutLine $ parse str | |
pure unit | |
where | |
writeStdoutLine :: String -> Eff (gzip :: GZIP, console :: CONSOLE, err :: EXCEPTION | eff) Boolean | |
writeStdoutLine line = writeString stdout UTF8 line (pure unit) | |
parse :: String -> String | |
parse logFile = joinWith "\n" $ parseLine <$> split "\n" logFile | |
where | |
parseLine :: String -> String | |
parseLine line = handleErrors $ getRayId <$> parseLog line |
module Main where
import Prelude (Unit)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE)
import Node.Process (stdin)
import Node.Stream (Readable)
foreign import createInterface :: forall r eff.
Readable r eff
-> Eff (console :: CONSOLE | eff) Unit
main = createInterface stdin
Same error as above.
The fix (thanks @paf31):
module Main where
import Prelude (Unit)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE)
import Node.Process (stdin)
import Node.Stream (Readable)
foreign import createInterface :: forall r eff.
Readable r (console :: CONSOLE | eff)
-> Eff (console :: CONSOLE | eff) Unit
main = createInterface stdin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error: