1

The Snap and Groundhog work separately but when combined (see below), snap crashes with a core-dump (segment fault or an access violation). These already worked together but problems started after ubuntu upgrade. (Or I have made some change I cannot see now.)

The snap works without wC <- getiCount -line. How to fix this one?

Addition based on comment: now there are logError messages around (SC refers to Snap.Core). When it crashes, it does not log any messages to log/error.log nor does it produce output to www-page. If runGH-line is commented and then next line used, all error messages and output to www-page is produced as expected.

2nd addition, inserted a separate file appends with wFile-function to show, where the program crashes: this shows that runGH2 is last addition to the file. Somehow the logErrorgives nothing (I tried runStdoutLogging) before crash. It seems that the program does not get to the iCount-function.

In Application.hs

runGH :: ConnectionManager b conn => DbPersist conn (NoLoggingT IO) a -> Handler b v a
runGH f = do 
  liftIO $ wFile "runGH"
  withTop' id $ do
    cm <- ask
    SC.logError "runGH2" 
    liftIO $ wFile "runGH2"
    liftIO $ runNoLoggingT (withConn (runDbPersist f) cm)

wFile txt = withFile "fmsg.txt" AppendMode $ \h -> hPutStrLn h ("log msg: " ++ txt)

and in Site.hs

initDBP :: (MonadIO m, MonadBaseControl IO m) => m (Pool Sqlite)
initDBP = withSqlitePool "mydb.sqlite" 5 $ \pconn -> return pconn

handleCntPage :: Handler App ({- AuthManager -} App) ()
handleCntPage = do 
    SC.logError "handleCntPage, 1st line"
    writeText $ T.pack ("Soon we count number of db-items. " )
    wC <- getiCount
    SC.logError "handleCntPage, almost last line"
    writeText $ T.pack ("we count number of db-items." ++ (show wC))

getiCount :: (ConnectionManager b conn, PersistBackend (DbPersist conn (NoLoggingT IO))) => Handler b v Int
getiCount = do
  liftIO $ wFile "getiCount"
  SC.logError "getiCount, 1st line"
  i <- runGH $ iCount -- this does not work
  liftIO $ wFile "getiCount2"
  -- let i = 10 -- this works
  SC.logError "getiCount, after call"
  return i

and iCount has been tested separately and it works without snap:

iCount :: (PersistBackend m) => m Int
iCount = do
   liftIO $ wFile "iCount"
   i <- countAll (undefined :: Items)
   liftIO $ wFile "iCount2"
   -- let i = 10 -- commenting the above line and using this one still crashes
   return i
5
  • You can put debug statements around countAll and getiCount and see where it fails. Sometimes that may happen in Haskell when there are broken dependencies. In this case rebuilding everything, for example, in cabal-sandbox can help.
    – Boris
    Dec 27, 2013 at 21:02
  • There are now some messages around with a short description above. The code is compiled with "cabal clean; cabal install -fdevelopment", Next, I'll try get familiar with the cabal-sandbox.
    – Gspia
    Dec 28, 2013 at 15:04
  • You rebuilt your project only. In a sandbox all libraries will be rebuilt too. If you put log inside of iCount, we can see if countAll or runGH triggers the error.
    – Boris
    Dec 28, 2013 at 16:21
  • Now there is more logging information through separate file writes. runGH-function would seem to be the source of problems this time... iCount was easy to test separately and it works. About sandbox: my cabal version is 1.16 so sandboxing will take some time (I haven't tried to build things directly from git, even though an intro seemed to be manageable).
    – Gspia
    Dec 28, 2013 at 20:11
  • And now the sandbox-experience shows something positive: this works as expected now. After removing sandbox, it does not - maybe I'll use sandbox from now on. If you answer this question with e.g. "check you libs with sandbox", I'll accept it right away. (This still leaves another question open on what are the lib's that don't work together - anyhow I'm happy now with sandbox.)
    – Gspia
    Dec 28, 2013 at 22:13

1 Answer 1

1

I think that all libraries you use are compatible. However, some packages got broken. Maybe Ubuntu upgrade replaced Haskell packages you installed via software center instead of cabal. Cabal sandbox would help for this particular project, but removing all packages and rebuilding them will prevent similar problems for other projects too.

My cabal packages are FUBAR; how can I purge them and start over?

1
  • Ok, first all ghc packages away from my ubuntu installation and then removal of user installed cabal packages. After these, install again ghc, cabal-install and haskell-platform with ubuntu package manager. Then newer cabal from git, and then with cabal install snap, groundhog, text-icu, maybe some other package. And now the program works as expected. I noticed that my cabal file for the project is not ok, it refers to some old versions thus building old unwanted versions. I'll have to remove those and try again but in case everything seems to be a bit better now.
    – Gspia
    Dec 29, 2013 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.