10

I'm trying to install my first scaffolded Yesod app. When I run cabal-dev install && yesod --dev devel it fails with ExitFailure 1. I'm using sqlite for persistent.

Application.hs:49:44:
No instance for (monad-logger-0.3.1:Control.Monad.Logger.MonadLogger
                   IO)
  arising from a use of `runMigration'
Possible fix:
  add an instance declaration for
  (monad-logger-0.3.1:Control.Monad.Logger.MonadLogger IO)
In the second argument of `Database.Persist.Store.runPool', namely
  `(runMigration migrateAll)'
In a stmt of a 'do' block:
  Database.Persist.Store.runPool dbconf (runMigration migrateAll) p
In the expression:
  do { manager <- newManager def;
       s <- staticSite;
       dbconf <- withYamlEnvironment
                   "config/sqlite.yml" (appEnv conf) Database.Persist.Store.loadConfig
                 >>= Database.Persist.Store.applyEnv;
       p <- Database.Persist.Store.createPoolConfig
              (dbconf :: PersistConfig);
       .... }
Failed to install testProject-0.0.0
cabal.exe: Error: some packages failed to install:
testProject-0.0.0 failed during the building phase. The exception was:
ExitFailure 1

I've tried to follow the instructions here: http://www.yesodweb.com/book/scaffolding-and-the-site-template Haven't managed to find any information regarding this problem. Any clues as to what's missing?

Joar Leth
  • 691
  • 9
  • 27

4 Answers4

7

Use one of the runFooLoggingT functions from Control.Monad.Logger. In particular there's runNoLoggingT.

This is probably a much, much better idea than fixing yourself to an old version of the library!

Colin Barrett
  • 4,451
  • 1
  • 26
  • 33
  • I'm getting a related (I think) compile error when trying to compile the email authentication example on [this page](http://www.yesodweb.com/book-1.1/authentication-and-authorization). The compile error is "No instance for (Control.Monad.Logger.MonadLogger IO) arising from a use of `runMigration'. If you think it would help, could you give some hints on where to insert runNoLoggingT in that code? I'm guessing that goes somewhere in main at the bottom of the page, not sure where. – Tad Aug 03 '13 at 20:42
  • Putting runNoLoggingT at the front of main did the trick. Here's the main that compiles: `main – Tad Aug 03 '13 at 21:34
  • Ran out of time on previous comment.... Putting runNoLoggingT at the front of main in the source I linked to did the trick. I also needed to add a liftIO before warpDebug. I'd paste the fixed code here for others to see, but I don't know how to paste code to a comment. Thanks to Colin for the big hint! – Tad Aug 03 '13 at 21:41
4

The error message says that the MonadLogger IO instance is missing. The problem is that the installed version of monad-logger is too new. monad-logger-0.2.4 includes the instance you need, monad-logger-0.3.0 and above apparently don't.

The solution: Add && < 0.3.0 to the monad-logger line in your cabal file and do cabal install --only-dependencies again.

(If there is no monad-logger line, add one like , monad-logger < 0.3.0.

mrueg
  • 8,185
  • 4
  • 44
  • 66
4

I'm still getting comfortable with transformers, so following Colin's answer, this is a very quick way to disable logging completely:

import Control.Monad.Logger (MonadLogger, monadLoggerLog)
import Control.Applicative  (pure)

instance MonadLogger IO where
    monadLoggerLog _ _ _ = pure $ pure ()

It basically reimplements the NoLoggingT instance for MonadIO.

However, once you get this quick fix on your codebase, you should head to the Monad Transformers page at the Haskell Wiki as I'm doing right now ; )

0

FYI, I overcame this by wrapping the value provided to withSqliteConn as argument with the NoLoggingT constructor, which allowed withSqliteConn to find MonadLogger somewhere in the stack, and I unwrapped the returned result with runNoLoggingT

mainWithExplicitConnection2:: IO ()
mainWithExplicitConnection2 =
    runNoLoggingT $ withSqliteConn ":memory:" $ \conn ->
        NoLoggingT $ flip runSqlPersistM conn $ runMigration migrateAll
nicolas
  • 9,549
  • 3
  • 39
  • 83