Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.tmp/
.stack-work/
node_modules/
.dir-locals.el
22 changes: 16 additions & 6 deletions effectful-config-file/src/Data/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Control.Exception (IOException, tryJust)
import Control.Monad (guard, void, (<=<))
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B (pack)
import Data.Functor ((<&>))
import Data.List (isPrefixOf)
import Data.Text (Text)
import qualified Data.Text as T (pack, unpack)
Expand Down Expand Up @@ -145,7 +146,11 @@ instance (FromValue a, Typeable a) => FromValue (ConfigValue a) where
either
(\e -> warnAt l (errorBundlePretty e) >> fromValue v)
pure
(runParser configValueParser ("ConfigValue " <> show (typeOf @a undefined)) (T.unpack t))
( runParser
configValueParser
("ConfigValue " <> show (typeOf @a undefined))
(T.unpack t)
)
fromValue v = Literal <$> fromValue v

-- | Wraps a config value fetch in a @config.fetch@ span tagged with the
Expand All @@ -158,7 +163,11 @@ withConfigSpan
-> Eff es a
withConfigSpan source key act = do
tp <- getGlobalTracerProvider
let tracer = makeTracer tp (instrumentationLibrary "effectful-config-file" "0.1.0.0") tracerOptions
let tracer =
makeTracer
tp
(instrumentationLibrary "effectful-config-file" "0.1.0.0")
tracerOptions
inSpan' tracer "config.fetch" defaultSpanArguments $ \sp -> do
addAttribute sp "config.source" source
addAttribute sp "config.key" key
Expand All @@ -177,7 +186,10 @@ tryMissing sp io = do
addAttribute sp "config.found" (either (const False) (const True) r)
pure r

rethrowMissing :: IOE :> es => Either IOException b -> Eff es b
rethrowMissing
:: IOE :> es
=> Either IOException b
-> Eff es b
rethrowMissing = either (liftIO . ioError) pure

instance ConfigParse a => ConfigFetch (ConfigValue a) where
Expand All @@ -193,9 +205,7 @@ instance ConfigParse a => ConfigFetch (ConfigValue a) where
$ \sp -> do
fp' <-
if "~/" `isPrefixOf` fp
then do
home <- liftIO getHomeDirectory
pure $ home </> drop 2 fp
then liftIO getHomeDirectory <&> (</> drop 2 fp)
else pure fp

logDebug $ "fetching config value from file " <> T.pack fp
Expand Down
6 changes: 5 additions & 1 deletion effectful-config-file/src/Effectful/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ readConfig'
-> Eff es c
readConfig' path = do
tp <- getGlobalTracerProvider
let tracer = makeTracer tp (instrumentationLibrary "effectful-config-file" "0.1.0.0") tracerOptions
let tracer =
makeTracer
tp
(instrumentationLibrary "effectful-config-file" "0.1.0.0")
tracerOptions
inSpan' tracer "config.read" defaultSpanArguments $ \sp -> do
addAttribute sp "config.path" (T.pack path)
processResult . decode' =<< liftIO (T.readFile path)
Expand Down
3 changes: 2 additions & 1 deletion effectful-config-file/src/Effectful/Config/Log.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ data Log :: Effect

type instance DispatchOf Log = Static WithSideEffects

newtype instance StaticRep Log = Log (Loc -> LogSource -> LogLevel -> LogStr -> IO ())
newtype instance StaticRep Log
= Log (Loc -> LogSource -> LogLevel -> LogStr -> IO ())

-- | Run the t'Log' effect with a @monad-logger@ style logging function.
--
Expand Down
Loading
Loading