on master help sign in
More exception catching
8c528ddMichael Snoyman
Helper.hsnew file+3
@@ -0,0 +1,3 @@
1+module Helper where
2+
3+db = "test.db3"
Network/Wai/Handler/DevelServer.hs+6−5
@@ -50,12 +50,15 @@ fillApp :: String -> String -> M.MVar Queue -> IO ()
50fillApp modu func mqueue =
50fillApp modu func mqueue =
51 go Nothing []
51 go Nothing []
52 where
52 where
53+ constSE :: x -> SomeException -> x
54+ constSE = const
55+ getTimes = handle (constSE $ return []) . mapM getModificationTime
53 go prevError prevFiles = do
56 go prevError prevFiles = do
54 toReload <-
57 toReload <-
55 if null prevFiles
58 if null prevFiles
56 then return True
59 then return True
57 else do
60 else do
58− times <- mapM (getModificationTime . fst) prevFiles
61+ times <- getTimes $ map fst prevFiles
59 return $ times /= map snd prevFiles
62 return $ times /= map snd prevFiles
60 (newError, newFiles) <-
63 (newError, newFiles) <-
61 if toReload
64 if toReload
@@ -76,10 +79,8 @@ fillApp modu func mqueue =
76 putStrLn "Interpreting success, new app loaded"
79 putStrLn "Interpreting success, new app loaded"
77 E.handle onInitErr $ do
80 E.handle onInitErr $ do
78 swapApp app mqueue
81 swapApp app mqueue
79− files' <- forM files $ \f -> do
82+ times <- getTimes files
80− t <- getModificationTime f
81− return (f, t)
82− return (Nothing, files')
83+ return (Nothing, zip files times)
83 onInitErr e = do
84 onInitErr e = do
84 putStrLn $ "Error initializing application: " ++ show e
85 putStrLn $ "Error initializing application: " ++ show e
85 loadingApp' (Just e) mqueue
86 loadingApp' (Just e) mqueue
TestApp.hs+1−1
@@ -7,6 +7,7 @@ import Data.ByteString.Lazy.Char8 (pack)
7import Database.Persist.Sqlite
7import Database.Persist.Sqlite
8import System.Directory
8import System.Directory
9import Control.Monad (when)
9import Control.Monad (when)
10+import Helper
10
11
11mkPersist [$persist|
12mkPersist [$persist|
12Dummy
13Dummy
@@ -15,7 +16,6 @@ Dummy
15
16
16testApp handler = do
17testApp handler = do
17 putStrLn "testApp called, this should happen only once per reload"
18 putStrLn "testApp called, this should happen only once per reload"
18− let db = "test.db3"
19 -- Swap between the following two lines as necessary to generate errors
19 -- Swap between the following two lines as necessary to generate errors
20 exi <- doesFileExist db
20 exi <- doesFileExist db
21 --let exi = True
21 --let exi = True