-- | This is designed to be used as
--
-- > import qualified Yesod.Core.Unsafe as Unsafe
--
-- This serves as a reminder that the functions are unsafe to use in many situations.
module Yesod.Core.Unsafe (runFakeHandler, fakeHandlerGetLogger) where

import Yesod.Core.Internal.Run (runFakeHandler)

import Yesod.Core.Types
import Yesod.Core.Class.Yesod
import Control.Monad.IO.Class (MonadIO)

-- | designed to be used as
--
-- > unsafeHandler = Unsafe.fakeHandlerGetLogger appLogger
fakeHandlerGetLogger :: (Yesod site, MonadIO m)
                     => (site -> Logger)
                     -> site
                     -> HandlerFor site a
                     -> m a
fakeHandlerGetLogger :: (site -> Logger) -> site -> HandlerFor site a -> m a
fakeHandlerGetLogger site -> Logger
getLogger site
app HandlerFor site a
f =
     SessionMap
-> (site -> Logger)
-> site
-> HandlerFor site a
-> m (Either ErrorResponse a)
forall site (m :: * -> *) a.
(Yesod site, MonadIO m) =>
SessionMap
-> (site -> Logger)
-> site
-> HandlerFor site a
-> m (Either ErrorResponse a)
runFakeHandler SessionMap
forall a. Monoid a => a
mempty site -> Logger
getLogger site
app HandlerFor site a
f
 m (Either ErrorResponse a)
-> (Either ErrorResponse a -> m a) -> m a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ErrorResponse -> m a)
-> (a -> m a) -> Either ErrorResponse a -> m a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ([Char] -> m a
forall a. HasCallStack => [Char] -> a
error ([Char] -> m a)
-> (ErrorResponse -> [Char]) -> ErrorResponse -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char]
"runFakeHandler issue: " [Char] -> [Char] -> [Char]
forall a. Monoid a => a -> a -> a
`mappend`) ([Char] -> [Char])
-> (ErrorResponse -> [Char]) -> ErrorResponse -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorResponse -> [Char]
forall a. Show a => a -> [Char]
show)
            a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return