Skip to content

Commit

Permalink
Print error with exit code when error occured
Browse files Browse the repository at this point in the history
  • Loading branch information
AiOO authored and Hyojun Kang committed Mar 10, 2017
1 parent c724fea commit 97b9138
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/Nirum/Cli.hs
Expand Up @@ -23,6 +23,7 @@ import System.Console.CmdArgs.Implicit ( Data
)
import System.Console.CmdArgs.Default (def)
import System.Directory (createDirectoryIfMissing)
import System.Exit (die)
import System.FilePath (takeDirectory, (</>))
import Text.InterpolatedString.Perl6 (qq)
import Text.Megaparsec (Token)
Expand Down Expand Up @@ -138,27 +139,27 @@ main' = do
result <- buildPackage "python" src
case result of
Left (TargetNameError targetName) ->
putStrLn [qq|Couldn't find "$targetName" target.|]
die [qq|Couldn't find "$targetName" target.|]
Left (PackageError (ParseError modulePath error')) -> do
{- FIXME: find more efficient way to determine filename from
the given module path -}
filePaths <- scanModules src
case M.lookup modulePath filePaths of
Just filePath' -> do
m <- parseErrortoPrettyMessage error' filePath'
putStrLn m
Nothing -> putStrLn [qq|$modulePath not found|]
die m
Nothing -> die [qq|$modulePath not found|]
Left (PackageError (ImportError importErrors)) ->
putStrLn [qq|Import error:
die [qq|Import error:
{importErrorsToPrettyMessage importErrors}
|]
Left (PackageError (ScanError _ error')) ->
putStrLn [qq|Scan error: $error'|]
die [qq|Scan error: $error'|]
Left (PackageError (MetadataError error')) ->
putStrLn [qq|Metadata error: $error'|]
die [qq|Metadata error: $error'|]
Left (CompileError errors) ->
forM_ (M.toList errors) $ \ (filePath, compileError) ->
putStrLn [qq|error: $filePath: $compileError|]
die [qq|error: $filePath: $compileError|]
Right buildResult -> writeFiles outDir buildResult

writeFiles :: FilePath -> BuildResult -> IO ()
Expand All @@ -170,4 +171,4 @@ writeFiles outDir files =
B.writeFile outPath code

main :: IO ()
main = catchIOError main' $ putStrLn . ioeGetErrorString
main = catchIOError main' $ die . ioeGetErrorString

0 comments on commit 97b9138

Please sign in to comment.