@@ -12,6 +12,7 @@ import Control.Monad.Eff.Class (liftEff)
1212import Control.Monad.Eff.Exception (Error ())
1313import Control.Monad.Error.Class (catchError , throwError )
1414
15+ import Data.Either (Either (..), either )
1516import Data.Foreign (Foreign ())
1617import Data.Foreign.Class (IsForeign , read , readProp )
1718import Data.Maybe (Maybe (Just), maybe , fromMaybe )
@@ -72,8 +73,9 @@ foreign import cwd "var cwd = process.cwd();" :: String
7273
7374foreign import argv " var argv = process.argv.slice(2);" :: [String ]
7475
75- pluginError :: forall eff . String -> Aff (Effects eff ) Error
76- pluginError msg = liftEff $ flip mkPluginError msg <$> (maybe " " (\(Package a) -> a.name)) <$> package
76+ throwPluginError :: forall eff . String -> Aff (Effects eff ) _
77+ throwPluginError msg = liftEff (flip mkPluginError msg <$> (maybe " " (\(Package a) -> a.name))
78+ <$> package) >>= throwError
7779
7880resolve :: forall eff . String -> [String ] -> Aff (Effects eff ) (Tuple String [String ])
7981resolve cmd args = catchError primary fallback
@@ -90,9 +92,7 @@ resolve cmd args = catchError primary fallback
9092 fallback _ = (const $ tuple2 cmd args) <$> catchError (which cmd) mapError
9193
9294 mapError :: Error -> Aff (Effects eff ) String
93- mapError _ = pluginError ( " Failed to find " ++ cmd ++ " . " ++
94- " Please ensure it is available on your system."
95- ) >>= throwError
95+ mapError _ = throwPluginError (" Failed to find " ++ cmd ++ " . " ++ " Please ensure it is available on your system." )
9696
9797execute :: forall eff . String -> [String ] -> Aff (Effects eff ) String
9898execute cmd args = do
@@ -103,30 +103,35 @@ execute cmd args = do
103103pathsStream :: forall eff . Eff (through2 :: Through2 | eff ) (Stream File [String ])
104104pathsStream = accStream run
105105 where run i = if fileIsStream i
106- then pluginError " Streaming is not supported" >>= throwError
106+ then throwPluginError " Streaming is not supported"
107107 else pure $ filePath i
108108
109109psc :: forall eff . Foreign -> Eff (Effects eff ) (Stream File File )
110110psc opts = multipipe2 <$> pathsStream <*> objStream run
111111 where run i = case pscOptionsNoOutput opts of
112- Tuple out opt ->
112+ Left e -> throwPluginError (show e)
113+ Right (Tuple out opt) ->
113114 mkFile (fromMaybe pscOutputDefault out) <$> mkBufferFromString
114115 <$> execute pscCommand (i <> opt)
115116
116117pscMake :: forall eff . Foreign -> Eff (Effects eff ) (Stream File Unit )
117118pscMake opts = multipipe2 <$> pathsStream <*> objStream run
118- where run i = do output <- execute pscMakeCommand (i <> pscMakeOptions opts)
119+ where run i = do output <- either (throwPluginError <<< show)
120+ (\a -> execute pscMakeCommand (i <> a))
121+ (pscMakeOptions opts)
119122 if isVerbose
120123 then liftEff $ info $ pscMakeCommand ++ " \n " ++ output
121124 else pure unit
122125
123126pscDocs :: forall eff . Foreign -> Eff (Effects eff ) (Stream File File )
124127pscDocs opts = multipipe2 <$> pathsStream <*> objStream run
125- where run i = mkFile " ." <$> mkBufferFromString
126- <$> execute pscDocsCommand (pscDocsOptions opts <> i)
128+ where run i = case pscDocsOptions opts of
129+ Left e -> throwPluginError (show e)
130+ Right a-> mkFile " ." <$> mkBufferFromString
131+ <$> execute pscDocsCommand (a <> i)
127132
128133dotPsci :: forall eff . Eff (Effects eff ) (Stream File Unit )
129134dotPsci = multipipe2 <$> objStream run <*> createWriteStream psciFilename
130135 where run i = if fileIsStream i
131- then pluginError " Streaming is not supported" >>= throwError
136+ then throwPluginError " Streaming is not supported"
132137 else pure $ psciLoadCommand ++ " " ++ relative cwd (filePath i) ++ " \n "
0 commit comments