Skip to content

Print error with exit code when error occured #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/Nirum/Cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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 @@ -148,7 +149,7 @@ main' = do
result <- buildPackage target src
case result of
Left (TargetNameError targetName') ->
putStrLn [qq|$targetName': No such target.
die [qq|Couldn't find "$targetName'" target.
Available targets: $targetNamesText|]
Left (PackageError (ParseError modulePath error')) -> do
{- FIXME: find more efficient way to determine filename from
Expand All @@ -157,19 +158,19 @@ Available targets: $targetNamesText|]
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 @@ -181,4 +182,4 @@ writeFiles outDir files =
B.writeFile outPath code

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