@@ -2,13 +2,16 @@
22{-# LANGUAGE LambdaCase #-}
33{-# LANGUAGE RecordWildCards #-}
44{-# LANGUAGE TemplateHaskell #-}
5+{-# LANGUAGE TypeApplications #-}
56
67module Main
78 ( main,
89 )
910where
1011
12+import Control.Exception (SomeException, displayException, try)
1113import Control.Monad
14+import Data.Either (lefts)
1215import Data.List (intercalate, sort)
1316import qualified Data.Text.IO as TIO
1417import Data.Version (showVersion)
@@ -29,7 +32,16 @@ main = withPrettyOrmoluExceptions $ do
2932 case optInputFiles of
3033 [] -> formatOne' Nothing
3134 ["-"] -> formatOne' Nothing
32− xs -> mapM_ (formatOne' . Just) xs
35+ [x] -> formatOne' (Just x)
36+ xs -> do
37+ -- It is possible to get IOException, error's and 'OrmoluException's
38+ -- from 'formatOne', so we just catch everything.
39+ errs <-
40+ lefts <$> mapM (try @SomeException . formatOne' . Just) xs
41+ unless (null errs) $ do
42+ hPutStrLn stderr "Some files failed to format:\n"
43+ mapM_ (hPutStrLn stderr . displayException) errs
44+ exitWith (ExitFailure 102)
3345
3446-- | Format a single input.
3547formatOne ::