From 046ca13356813af0817a7b3744315d012832fe2e Mon Sep 17 00:00:00 2001 From: Andrew Martin Date: Mon, 19 Aug 2019 11:12:48 -0400 Subject: Add predicates for testing if IOError is ResourceVanished. This adds isResourceVanished, resourceVanishedErrorType, and isResourceVanishedErrorType to System.IO.Error, resolving #14730. --- libraries/base/System/IO/Error.hs | 26 ++++++++++++++++++++++++++ libraries/base/changelog.md | 3 +++ 2 files changed, 29 insertions(+) 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* -- cgit v1.2.1