I was trying to call createDirectory and catching isAlreadyExistError in order to do nothing in this case. I realized then that there is createDirectoryIfMissing and use it. But still I’m puzzled by the documentation for createDirectory, which says that:
`isAlreadyExistsError` The operand refers to a directory that already exists. [EEXIST]
Which leads me to believe that I can catch an IOException and do an if isAlreadyExistsError e .... But that doesn’t seem possible, because the predicate is in a private module.
It’s definitely System.IO.Error. The directory package Internal.Prelude re-exports definitions and under haddock that makes it seem like the function is definied within the directory package. I found this behaviour useful in a personal project, but I can see it very easily becoming confusing.
Confusing indeed. I click on ìsAlreadyExistError` and get to a (for me) relatively random module and then have to Hoogle search my way to the right function?
hideError :: (MonadIO m, MonadCatch m) => IOErrorType -> m () -> m ()
hideError err = handleIO (\e -> if err == ioeGetErrorType e then pure () else liftIO . ioError $ e)
hideErrorDef :: (MonadIO m, MonadCatch m) => IOErrorType -> a -> m a -> m a
hideErrorDef err def =
handleIO (\e -> if err == ioeGetErrorType e then pure def else liftIO $ ioError e)
(can also expand it to hideErrors :: [IOErrorType] -> ...)