@@ -225,10 +225,10 @@ foreign import ccall unsafe "fdopen"
225225 -> IO File
226226foreign import ccall unsafe "fclose"
227227 c_fclose :: File
228− -> IO ()
228+ -> IO CInt
229229
230230foreign import ccall unsafe "fclose_helper"
231− c_fclose_helper :: File -> IO ()
231+ c_fclose_helper :: File -> IO CInt
232232
233233foreign import ccall unsafe "yaml_parser_parse"
234234 c_yaml_parser_parse :: Parser -> EventRaw -> IO CInt
@@ -659,7 +659,8 @@ decodeFileMarked file =
659659 c_yaml_parser_set_input_file ptr file'
660660 return (ptr, file')
661661 cleanup (ptr, file') = do
662− c_fclose_helper file'
662+ res <- c_fclose_helper file'
663+ when (res /= 0) $ throwIO $ YamlException $ "could not close file: " ++ file
663664 c_yaml_parser_delete ptr
664665 free ptr
665666
@@ -791,8 +792,12 @@ encodeFileWith :: MonadResource m
791792 -> FilePath
792793 -> ConduitM Event o m ()
793794encodeFileWith opts filePath =
794− bracketP getFile c_fclose $ \file -> runEmitter opts (alloc file) (\u _ -> return u)
795+ bracketP getFile cleanup $ \file -> runEmitter opts (alloc file) (\u _ -> return u)
795796 where
797+ cleanup file = do
798+ res <- c_fclose file
799+ when (res /= 0) $ throwIO $ YamlException $ "could not close file: " ++ filePath
800+
796801 getFile = do
797802#if WINDOWS && __GLASGOW_HASKELL__ >= 806
798803 -- See: https://github.com/snoyberg/yaml/issues/178#issuecomment-550180027