Skip to content

Instantly share code, notes, and snippets.

@maddie927
Last active January 21, 2016 21:46
Show Gist options
  • Save maddie927/83c66a1e76d1b937aba7 to your computer and use it in GitHub Desktop.
Save maddie927/83c66a1e76d1b937aba7 to your computer and use it in GitHub Desktop.
build error
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
@maddie927
Copy link
Author

Error:

Error found:
in module Main
at ./src/Main.purs line 37, column 1 - line 38, column 1

  Label "console" appears more than once in a row type.
  Relevant expression:

    createInterface (Input { input: ...
                           }
                    )


in value declaration main


See https://github.com/purescript/purescript/wiki/Error-Code-DuplicateLabel for more information,
or to contribute content related to this error.

@maddie927
Copy link
Author

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.

@maddie927
Copy link
Author

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