on master help sign in
Don't give up on first failure when multiple files are given

Closes #502.

commit34dc1cba49bc05a78bb05b8974c3250d25982a05 authorUtku Demir <me@utdemir.com> dateTue 28 Jan 2020, 09:47 (7 years ago) parenta9f8926
2 files changed+19−1
CHANGELOG.md+6 app/Main.hs+13−1
CHANGELOG.md+6
@@ -1,3 +1,9 @@
1+## Unreleased
2+
3+* When given several files to format, Ormolu does not stop on the first
4+ failure, but tries to format all the files. [Issue
5+ 502](https://github.com/tweag/ormolu/issues/502).
6+
17## Ormolu 0.0.3.1
28
39* Fixed rendering of record updates with the record dot preprocessor syntax
app/Main.hs+13−1
@@ -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 ::