Skip to content

Commit 65b0f8f

Browse files
committed
Merge branch 'no-async'
2 parents c66d56a + 5c68a44 commit 65b0f8f

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

System/FilePath/Internal.hs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ import Data.List(stripPrefix, isSuffixOf, uncons, dropWhileEnd)
129129
#define STRING String
130130
#define FILEPATH FilePath
131131
#else
132-
import Prelude (fromIntegral)
133-
import Control.Exception ( SomeException, evaluate, try, displayException )
132+
import Prelude (fromIntegral, return, IO, Either(..))
133+
import Control.Exception ( catch, displayException, evaluate, fromException, toException, throwIO, Exception, SomeAsyncException(..), SomeException )
134134
import Control.DeepSeq (force)
135135
import GHC.IO (unsafePerformIO)
136136
import qualified Data.Char as C
@@ -1270,15 +1270,31 @@ snoc :: String -> Char -> String
12701270
snoc str = \c -> str <> [c]
12711271

12721272
#else
1273+
-- | Like 'try', but rethrows async exceptions.
1274+
trySafe :: Exception e => IO a -> IO (Either e a)
1275+
trySafe ioA = catch action eHandler
1276+
where
1277+
action = do
1278+
v <- ioA
1279+
return (Right v)
1280+
eHandler e
1281+
| isAsyncException e = throwIO e
1282+
| otherwise = return (Left e)
1283+
1284+
isAsyncException :: Exception e => e -> Bool
1285+
isAsyncException e =
1286+
case fromException (toException e) of
1287+
Just (SomeAsyncException _) -> True
1288+
Nothing -> False
12731289
#ifdef WINDOWS
12741290
fromString :: P.String -> STRING
12751291
fromString str = P.either (P.error . P.show) P.id $ unsafePerformIO $ do
1276-
r <- try @SomeException $ GHC.withCStringLen (mkUTF16le ErrorOnCodingFailure) str $ \cstr -> packCStringLen cstr
1292+
r <- trySafe @SomeException $ GHC.withCStringLen (mkUTF16le ErrorOnCodingFailure) str $ \cstr -> packCStringLen cstr
12771293
evaluate $ force $ first displayException r
12781294
#else
12791295
fromString :: P.String -> STRING
12801296
fromString str = P.either (P.error . P.show) P.id $ unsafePerformIO $ do
1281-
r <- try @SomeException $ GHC.withCStringLen (mkUTF8 ErrorOnCodingFailure) str $ \cstr -> packCStringLen cstr
1297+
r <- trySafe @SomeException $ GHC.withCStringLen (mkUTF8 ErrorOnCodingFailure) str $ \cstr -> packCStringLen cstr
12821298
evaluate $ force $ first displayException r
12831299
#endif
12841300

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
_Note: below all `FilePath` values are unquoted, so `\\` really means two backslashes._
44

5+
## 1.5.4.0 *Nov 2024*
6+
7+
* Don't catch async exceptions in internal functions wrt https://github.com/haskell/os-string/issues/22
8+
59
## 1.5.3.0 *Jun 2024*
610

711
* Adjust for `encodeFS`/`decodedFS` deprecation in os-string

filepath.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: filepath
3-
version: 1.5.3.0
3+
version: 1.5.4.0
44

55
-- NOTE: Don't forget to update ./changelog.md
66
license: BSD-3-Clause

0 commit comments

Comments
 (0)