packages feed

rio 0.1.23.0 → 0.1.24.0

raw patch · 4 files changed

+25/−10 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for rio
 
+## 0.1.24.0
+
+* Fix a bug in the `Utf8Builder` instance of `Monoid`, introduced in `rio-0.1.23.0`
+
 ## 0.1.23.0
 
 * Support GHC 9.14
rio.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12
 --- This file has been generated from package.yaml by hpack version 0.38.1.+-- This file has been generated from package.yaml by hpack version 0.38.2. -- -- see: https://github.com/sol/hpack  name:           rio-version:        0.1.23.0+version:        0.1.24.0 synopsis:       A standard library for Haskell description:    See README and Haddocks at <https://www.stackage.org/package/rio> category:       Control
src/RIO/Prelude/Display.hs view
@@ -1,4 +1,8 @@+{-# HLINT ignore "Use fold" #-}
+{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
+
 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
+
 module RIO.Prelude.Display
   ( Utf8Builder (..)
   , Display (..)
@@ -14,7 +18,6 @@ import qualified Data.ByteString.Lazy     as BL
 import qualified Data.ByteString.Builder  as BB
 import           Data.ByteString.Builder  (Builder)
-import           Data.Foldable            (fold)
 import           Data.Semigroup           (Semigroup(..))
 import           Data.Text                (Text)
 import qualified Data.Text.Lazy           as TL
@@ -38,9 +41,12 @@ instance Monoid Utf8Builder where
   mempty = Utf8Builder mempty
   {-# INLINE mempty #-}
+
   mappend = (Data.Semigroup.<>)
   {-# INLINE mappend #-}
-  mconcat = fold
+
+  -- Data.Foldable.fold cannot be used here because it results in a circularity:
+  mconcat = foldr mappend mempty
   {-# INLINE mconcat #-}
 
 -- | @since 0.1.0.0
src/RIO/Prelude/Logger.hs view
@@ -87,11 +87,11 @@ import Data.Bits
 import Data.ByteString.Builder (toLazyByteString, char7, byteString, hPutBuilder)
 import Data.ByteString.Builder.Extra (flush)
-import           GHC.IO.Handle.Internals         (wantWritableHandle)
 import           GHC.IO.Encoding.Types           (textEncodingName)
-import           GHC.IO.Handle.Types             (Handle__ (..))
 import qualified Data.ByteString as B
-import           System.IO                  (localeEncoding)
+import           System.IO                  (hGetEncoding, localeEncoding)
+import           System.IO.Error            (illegalOperationErrorType,
+                                             mkIOError, ioError)
 import           GHC.Foreign                (peekCString, withCString)
 import Data.Semigroup (Semigroup (..))
 
@@ -301,9 +301,14 @@ -- that encompasses the logSticky->logStickyDone pairing.
 
 canUseUtf8 :: MonadIO m => Handle -> m Bool
-canUseUtf8 h = liftIO $ wantWritableHandle "canUseUtf8" h $ \h_ -> do
-  -- TODO also handle haOutputNL for CRLF
-  return $ (textEncodingName <$> haCodec h_) == Just "UTF-8"
+canUseUtf8 h = liftIO $ do
+  isWritable <- hIsWritable h
+  unless isWritable $ ioError $ mkIOError illegalOperationErrorType
+                                          "canUseUtf8"
+                                          (Just h)
+                                          Nothing
+  maybeEnc <- hGetEncoding h
+  return $ fmap textEncodingName maybeEnc == Just "UTF-8"
 
 -- | Create a 'LogOptions' value which will store its data in
 -- memory. This is primarily intended for testing purposes. This will