on master help sign in
Raise informative error on failure to read $PORT
commitac1effe251aece45fe2b7378742fe21e4746f824 authorpatrick brisbin <pbrisbin@gmail.com> dateSun 8 Feb 2015, 13:39 (12 years ago) parentef8ceaa
1 file changed+8−1
warp/Network/Wai/Handler/Warp/Run.hs+8−1
warp/Network/Wai/Handler/Warp/Run.hs+8−1
@@ -80,7 +80,14 @@ run p = runSettings defaultSettings { settingsPort = p }
8080runEnv :: Port -> Application -> IO ()
8181runEnv p app = do
8282 mp <- fmap (lookup "PORT") getEnvironment
83− run (maybe p read mp) app
83+
84+ maybe (run p app) runReadPort mp
85+
86+ where
87+ runReadPort :: String -> IO ()
88+ runReadPort sp = case reads sp of
89+ ((p', _):_) -> run p' app
90+ _ -> fail $ "Invalid value in $PORT: " ++ sp
8491
8592-- | Run an 'Application' with the given 'Settings'.
8693runSettings :: Settings -> Application -> IO ()