Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

failWith: allow GetErrorMessage to return NULL (#3815)

  • Loading branch information...
commit bb0911571e5aae1486dcbf6069f0a8a6f3f0cd0b 1 parent 07a004a
Simon Marlow simonmar authored

Showing 1 changed file with 8 additions and 3 deletions. Show diff stats Hide diff stats

  1. +8 3 System/Win32/Types.hs
11 System/Win32/Types.hs
@@ -23,6 +23,7 @@ import Foreign.C
23 23 import Control.Exception
24 24 import System.IO.Error
25 25 import Data.Char
  26 +import Numeric (showHex)
26 27
27 28 ----------------------------------------------------------------
28 29 -- Platform specific definitions
@@ -204,9 +205,12 @@ errorWin fn_name = do
204 205 failWith :: String -> ErrCode -> IO a
205 206 failWith fn_name err_code = do
206 207 c_msg <- getErrorMessage err_code
207   - msg <- peekTString c_msg
208   - -- We ignore failure of freeing c_msg, given we're already failing
209   - _ <- localFree c_msg
  208 + msg <- if c_msg == nullPtr
  209 + then return $ "Error 0x" ++ Numeric.showHex err_code ""
  210 + else do msg <- peekTString c_msg
  211 + -- We ignore failure of freeing c_msg, given we're already failing
  212 + _ <- localFree c_msg
  213 + return msg
210 214 c_maperrno -- turn GetLastError() into errno, which errnoToIOError knows
211 215 -- how to convert to an IOException we can throw.
212 216 -- XXX we should really do this directly.
@@ -216,6 +220,7 @@ failWith fn_name err_code = do
216 220 `ioeSetErrorString` msg'
217 221 throw ioerror
218 222
  223 +
219 224 foreign import ccall unsafe "maperrno" -- in base/cbits/Win32Utils.c
220 225 c_maperrno :: IO ()
221 226

0 comments on commit bb09115

Please sign in to comment.
Something went wrong with that request. Please try again.