Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove orphan Show instance for Foreign.C.Error.Errno #54

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fs-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Breaking

* New `primitive ^>=0.9` dependency
* Remove orphan `Show` instance for `Foreign.C.Error.Errno`.

### Non-breaking

Expand Down
36 changes: 34 additions & 2 deletions fs-api/src/System/FS/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}

-- For Show Errno and Condense SeekMode instances
Expand Down Expand Up @@ -55,6 +56,7 @@ import Foreign.C.Error (Errno (..))
import qualified Foreign.C.Error as C
import GHC.Generics (Generic)
import qualified GHC.IO.Exception as GHC
import GHC.Show (showCommaSpace)
import System.FilePath
import System.IO (SeekMode (..))
import qualified System.IO.Error as IO
Expand Down Expand Up @@ -224,9 +226,39 @@ data FsError = FsError {
-- would not have thrown an error for these calls.
, fsLimitation :: Bool
}
deriving Show

deriving instance Show Errno
-- This is a custom instance and not an auto-derive one, since 'Errno' does not
-- have a 'Show' instance, and we don't want to provide an orphan instance for
-- this @base@ type.
instance Show FsError where
showsPrec n fserr = showParen (n >= 11) $
showString "FsError {"
. showString "fsErrorType = " . shows fsErrorType . showCommaSpace
. showString "fsErrorPath = " . shows fsErrorPath . showCommaSpace
. showString "fsErrorString = " . shows fsErrorString . showCommaSpace
. showString "fsErrorNo = " . showsFsErrNo fsErrorNo . showCommaSpace
. showString "fsErrorStack = " . shows fsErrorStack . showCommaSpace
. showString "fsLimitation = " . shows fsLimitation
. showString "}"
where
-- Quite a bit of boilerplate, but it should ensure that we won't silently
-- change/forget to change the Show instance when fields are
-- changed/re-ordered/added.
FsError {
fsErrorType = fsErrorType :: FsErrorType
, fsErrorPath = fsErrorPath :: FsErrorPath
, fsErrorString = fsErrorString :: String
, fsErrorNo = fsErrorNo :: Maybe Errno
, fsErrorStack = fsErrorStack :: PrettyCallStack
, fsLimitation = fsLimitation :: Bool
} = fserr
_coveredAllCases = case fserr of
FsError (_ :: FsErrorType) (_ :: FsErrorPath) (_ :: String)
(_ :: Maybe Errno) (_ :: PrettyCallStack) (_ :: Bool) -> ()

showsFsErrNo Nothing = showString "Nothing"
showsFsErrNo (Just (Errno e)) = showString "Just "
. showParen True (showString "Errno " . shows e)

data FsErrorType
= FsIllegalOperation
Expand Down
4 changes: 4 additions & 0 deletions fs-sim/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for fs-sim

## next release -- ????-??-??

* Orphan `Show` instance for `Foreign.C.Error.Errno` removed by `fs-api`.

## 0.2.1.1 -- 2023-10-30

### Patch
Expand Down