summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Martin <andrew.thaddeus@gmail.com>2019-08-19 11:12:48 -0400
committerAndrew Martin <andrew.thaddeus@gmail.com>2019-09-13 15:43:16 -0400
commit046ca13356813af0817a7b3744315d012832fe2e (patch)
tree06ccc56443182c54e6d2c8f7406a09e2e6ed8550
parenta0e220b77957738b9966a099b5616017ab7b05b6 (diff)
downloadhaskell-046ca13356813af0817a7b3744315d012832fe2e.tar.gz
Add predicates for testing if IOError is ResourceVanished.
This adds isResourceVanished, resourceVanishedErrorType, and isResourceVanishedErrorType to System.IO.Error, resolving #14730.
-rw-r--r--libraries/base/System/IO/Error.hs26
-rw-r--r--libraries/base/changelog.md3
2 files changed, 29 insertions, 0 deletions
diff --git a/libraries/base/System/IO/Error.hs b/libraries/base/System/IO/Error.hs
index 2de6629a89..2585181df8 100644
--- a/libraries/base/System/IO/Error.hs
+++ b/libraries/base/System/IO/Error.hs
@@ -35,6 +35,7 @@ module System.IO.Error (
isIllegalOperation,
isPermissionError,
isUserError,
+ isResourceVanishedError,
-- ** Attributes of I\/O errors
ioeGetErrorType,
@@ -60,6 +61,7 @@ module System.IO.Error (
illegalOperationErrorType,
permissionErrorType,
userErrorType,
+ resourceVanishedErrorType,
-- ** 'IOErrorType' predicates
isAlreadyExistsErrorType,
@@ -70,6 +72,7 @@ module System.IO.Error (
isIllegalOperationErrorType,
isPermissionErrorType,
isUserErrorType,
+ isResourceVanishedErrorType,
-- * Throwing and catching I\/O errors
@@ -170,6 +173,13 @@ isPermissionError = isPermissionErrorType . ioeGetErrorType
isUserError :: IOError -> Bool
isUserError = isUserErrorType . ioeGetErrorType
+-- | An error indicating that the operation failed because the
+-- resource vanished. See 'resourceVanishedErrorType'.
+--
+-- @since 0.4.14.0
+isResourceVanishedError :: IOError -> Bool
+isResourceVanishedError = isResourceVanishedErrorType . ioeGetErrorType
+
-- -----------------------------------------------------------------------------
-- IOErrorTypes
@@ -210,6 +220,14 @@ permissionErrorType = PermissionDenied
userErrorType :: IOErrorType
userErrorType = UserError
+-- | I\/O error where the operation failed because the resource vanished.
+-- This happens when, for example, attempting to write to a closed
+-- socket or attempting to write to a named pipe that was deleted.
+--
+-- @since 0.4.14.0
+resourceVanishedErrorType :: IOErrorType
+resourceVanishedErrorType = ResourceVanished
+
-- -----------------------------------------------------------------------------
-- IOErrorType predicates
@@ -258,6 +276,14 @@ isUserErrorType :: IOErrorType -> Bool
isUserErrorType UserError = True
isUserErrorType _ = False
+-- | I\/O error where the operation failed because the resource vanished.
+-- See 'resourceVanishedErrorType'.
+--
+-- @since 0.4.14.0
+isResourceVanishedErrorType :: IOErrorType -> Bool
+isResourceVanishedErrorType ResourceVanished = True
+isResourceVanishedErrorType _ = False
+
-- -----------------------------------------------------------------------------
-- Miscellaneous
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index e404442801..0f2c72a9ac 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -30,6 +30,9 @@
* `openTempFile` is now fully atomic and thread-safe on Windows.
+ * Add `isResourceVanishedError`, `resourceVanishedErrorType`, and
+ `isResourceVanishedErrorType` to `System.IO.Error`.
+
## 4.13.0.0 *TBA*
* Bundled with GHC *TBA*