aboutsummaryrefslogtreecommitdiff
path: root/CabalHelper/Compiletime/Log.hs
blob: ec38f8874614b6f4c365e3e3d6694c9f126ad76d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{-# LANGUAGE ScopedTypeVariables #-}

module CabalHelper.Compiletime.Log where

import Control.Monad
import Control.Monad.IO.Class
import Control.Exception as E
import Data.String
import System.IO
import Prelude

import CabalHelper.Compiletime.Types

vLog :: MonadIO m => Options -> String -> m ()
vLog Options { verbose = True } msg =
    liftIO $ hPutStrLn stderr msg
vLog _ _ = return ()

logIOError :: Options -> String -> IO (Maybe a) -> IO (Maybe a)
logIOError opts label a = do
  a `E.catch` \(ex :: IOError) -> do
      vLog opts $ label ++ ": " ++ E.displayException ex
      return Nothing