Skip to content

Commit f0d93ac

Browse files
Use stderr for errors (#2458)
* Use stderr for errors * Format with stylish-haskell Co-authored-by: andreiburdusa <andreiburdusa@users.noreply.github.com> Co-authored-by: rv-jenkins <admin@runtimeverification.com>
1 parent 66158c6 commit f0d93ac

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

kore/app/exec/Main.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import qualified Data.Text as Text
3434
, split
3535
)
3636
import qualified Data.Text.IO as Text
37-
( putStrLn
37+
( hPutStrLn
3838
, readFile
3939
)
4040
import qualified GHC.Generics as GHC
@@ -80,6 +80,7 @@ import System.FilePath
8080
)
8181
import System.IO
8282
( IOMode (WriteMode)
83+
, stderr
8384
, withFile
8485
)
8586

@@ -804,7 +805,7 @@ koreMerge execOptions mergeOptions = do
804805
Nothing -> mergeAllRules mainModule ruleIds
805806
case eitherMergedRule of
806807
(Left err) -> do
807-
lift $ Text.putStrLn err
808+
lift $ Text.hPutStrLn stderr err
808809
return (ExitFailure 1)
809810
(Right mergedRule) -> do
810811
let mergedRule' =

kore/app/repl/Main.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ import System.Clock
6363
)
6464

6565
import GlobalMain
66+
import System.IO
67+
( hPutStrLn
68+
, stderr
69+
)
6670

6771
-- | Represents a file name along with its module name passed.
6872
data KoreModule = KoreModule
@@ -213,7 +217,7 @@ mainWithOptions
213217
&& isNothing (unReplScript replScript)
214218
)
215219
$ lift $ do
216-
putStrLn
220+
hPutStrLn stderr
217221
"You must supply the path to the repl script\
218222
\ in order to run the repl in run-script mode."
219223
exitFailure
@@ -223,7 +227,7 @@ mainWithOptions
223227
&& scriptModeOutput == EnableOutput
224228
)
225229
$ lift $ do
226-
putStrLn
230+
hPutStrLn stderr
227231
"The --save-run-output flag is only available\
228232
\ when running the repl in run-script mode."
229233
exitFailure

kore/src/Kore/BugReport.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ withBugReport exeName bugReportOption act =
146146
optionalWriteBugReport tmpDir
147147
| Just (ioe :: IOException) <- fromException someException
148148
, NoSuchThing <- ioe_type ioe -> do
149-
putStrLn $ displayException someException
149+
hPutStrLn stderr $ displayException someException
150150
optionalWriteBugReport tmpDir
151151
| otherwise -> do
152152
let message = displayException someException

kore/src/Kore/Repl.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ import Kore.Attribute.RuleIndex
5454
import qualified Kore.Attribute.RuleIndex as Attribute
5555
import System.IO
5656
( hFlush
57+
, hPutStrLn
58+
, stderr
5759
, stdout
5860
)
5961
import Text.Megaparsec
@@ -274,7 +276,7 @@ runRepl
274276
catchInterruptWithDefault a =
275277
Exception.handle $ \case
276278
UserInterrupt -> do
277-
liftIO $ putStrLn "Step evaluation interrupted."
279+
liftIO $ hPutStrLn stderr "Step evaluation interrupted."
278280
pure a
279281
e -> Exception.throwM e
280282

kore/src/Kore/Repl/Interpreter.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ import System.FilePath
132132
)
133133
import System.IO
134134
( IOMode (..)
135+
, hPutStrLn
136+
, stderr
135137
, withFile
136138
)
137139
import System.Process
@@ -1191,7 +1193,7 @@ pipe cmd file args = do
11911193
outputFunc str
11921194
case maybeOutput of
11931195
Nothing ->
1194-
putStrLn "Error: couldn't access output handle."
1196+
hPutStrLn stderr "Error: couldn't access output handle."
11951197
Just handle -> do
11961198
output <- liftIO $ hGetContents handle
11971199
modifyIORef pipeOut (appReplOut . AuxOut $ output)
@@ -1517,11 +1519,11 @@ parseEvalScript file scriptModeOutput = do
15171519
contents <- lift . liftIO $ readFile file
15181520
let result = runParser scriptParser file (Text.pack contents)
15191521
either parseFailed executeScript result
1520-
else lift . liftIO . putStrLn $ "Cannot find " <> file
1522+
else lift . liftIO . hPutStrLn stderr $ "Cannot find " <> file
15211523

15221524
where
15231525
parseFailed err =
1524-
lift . liftIO . putStrLn
1526+
lift . liftIO . hPutStrLn stderr
15251527
$ "\nCouldn't parse repl script file."
15261528
<> "\nParser error at: "
15271529
<> (err & toReplScriptParseErrors & errorBundlePretty)
@@ -1619,4 +1621,4 @@ withExistingDirectory path action =
16191621
ifM
16201622
(doesParentDirectoryExist path)
16211623
(action path)
1622-
$ liftIO . putStrLn $ "Directory does not exist."
1624+
$ liftIO . hPutStrLn stderr $ "Directory does not exist."

0 commit comments

Comments
 (0)