on master help sign in
Better exception printing

* Don't print timeout exception by default. * Print out other exceptions as Text to avoid race conditions in output.

commit2a32eda3c6335ab7839e256e163f52ffa9f73042 authorMichael Snoyman <michael@snoyman.com> dateMon 24 Mar 2014, 22:10 (13 years ago) parent47003a3
3 files changed+12−3
warp/Network/Wai/Handler/Warp/Settings.hs+7−2 warp/Network/Wai/Handler/Warp/Timeout.hs+2 warp/warp.cabal+3−1
warp/Network/Wai/Handler/Warp/Settings.hs+7−2
@@ -4,6 +4,8 @@ module Network.Wai.Handler.Warp.Settings where
44
55import Control.Exception
66import qualified Data.ByteString as S
7+import qualified Data.Text as T
8+import qualified Data.Text.IO as TIO
79import qualified Data.ByteString.Lazy.Char8 as L8
810import Data.Conduit
911import Data.Conduit.Network (HostPreference (HostIPv4))
@@ -77,7 +79,7 @@ defaultSettings = Settings
7779defaultExceptionHandler :: Maybe Request -> SomeException -> IO ()
7880defaultExceptionHandler _ e = throwIO e `catches` handlers
7981 where
80− handlers = [Handler ah, Handler ih, Handler oh, Handler sh]
82+ handlers = [Handler ah, Handler ih, Handler oh, Handler th, Handler sh]
8183
8284 ah :: AsyncException -> IO ()
8385 ah ThreadKilled = return ()
@@ -93,8 +95,11 @@ defaultExceptionHandler _ e = throwIO e `catches` handlers
9395 where
9496 et = ioeGetErrorType x
9597
98+ th :: TimeoutThread -> IO ()
99+ th TimeoutThread = return ()
100+
96101 sh :: SomeException -> IO ()
97− sh x = hPrint stderr x
102+ sh = TIO.hPutStrLn stderr . T.pack . show
98103
99104defaultExceptionResponse :: SomeException -> Response
100105defaultExceptionResponse _ = responseLBS H.internalServerError500 [(H.hContentType, "text/plain")] "Something went wrong"
warp/Network/Wai/Handler/Warp/Timeout.hs+2
@@ -38,6 +38,8 @@ module Network.Wai.Handler.Warp.Timeout (
3838 , cancel
3939 , pause
4040 , resume
41+ -- * Exceptions
42+ , TimeoutThread (..)
4143 ) where
4244
4345#if MIN_VERSION_base(4,6,0)
warp/warp.cabal+3−1
@@ -1,5 +1,5 @@
11Name: warp
2−Version: 2.1.2
2+Version: 2.1.2.1
33Synopsis: A fast, light-weight web server for WAI applications.
44License: MIT
55License-file: LICENSE
@@ -48,6 +48,7 @@ Library
4848 , unix-compat >= 0.2
4949 , void
5050 , wai >= 2.1 && < 2.2
51+ , text
5152 if flag(network-bytestring)
5253 Build-Depends: network >= 2.2.1.5 && < 2.2.3
5354 , network-bytestring >= 0.1.3 && < 0.1.4
@@ -135,6 +136,7 @@ Test-Suite spec
135136 , hspec >= 1.3
136137 , time
137138 , old-locale
139+ , text
138140
139141 if (os(linux) || os(freebsd) || os(darwin)) && flag(allow-sendfilefd)
140142 Cpp-Options: -DSENDFILEFD