From e3df353e1cbd04c4824960f629319d1b9082b18e Mon Sep 17 00:00:00 2001 From: Brad Neimann Date: Thu, 18 Jul 2019 14:27:26 +1000 Subject: [PATCH] Inhibit errors from terminal-size When attempting to detect the size of a Windows terminal, stty can sometimes fail with an error message, which the terminal-size package then prints to the console. This causes unexpected error messages when attempting to use Stack in such a terminal. These error messages can also interfere with tools such as Intero, which rely on Stack's output. --- ChangeLog.md | 3 +++ package.yaml | 1 + src/Stack/Runners.hs | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 6e9fe15352..129eae1c41 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -19,6 +19,9 @@ Other enhancements: Bug fixes: +* Errors from the `terminal-size` package are now silenced. See + [#4901](https://github.com/commercialhaskell/stack/issues/4901) + ## v2.1.3.1 diff --git a/package.yaml b/package.yaml index b12aae76ef..fb4801ead8 100644 --- a/package.yaml +++ b/package.yaml @@ -108,6 +108,7 @@ dependencies: - rio - rio-prettyprint - semigroups +- silently - split - stm - streaming-commons diff --git a/src/Stack/Runners.hs b/src/Stack/Runners.hs index 7d666dbad3..5af148204f 100644 --- a/src/Stack/Runners.hs +++ b/src/Stack/Runners.hs @@ -36,6 +36,8 @@ import Stack.Types.Nix (nixEnable) import Stack.Types.Version (stackMinorVersion, stackVersion, minorVersion) import System.Console.ANSI (hSupportsANSIWithoutEmulation) import System.Console.Terminal.Size (size, width) +import System.IO.Silently (hSilence) +import System.IO (stderr) -- | Ensure that no project settings are used when running 'withConfig'. withGlobalProject :: RIO Runner a -> RIO Runner a @@ -145,8 +147,10 @@ withRunnerGlobal go inner = do ColorAlways -> return True ColorAuto -> fromMaybe True <$> hSupportsANSIWithoutEmulation stderr + -- In certain situations the call to 'size' prints error messages on stderr even when the operation + -- succeeds, so we silence stderr to avoid these errors termWidth <- clipWidth <$> maybe (fromMaybe defaultTerminalWidth - <$> fmap (fmap width) size) + <$> fmap (fmap width) (hSilence [stderr] size)) pure (globalTermWidth go) menv <- mkDefaultProcessContext logOptions0 <- logOptionsHandle stderr False