Skip to content

Add a variant of the envQ which fails at compile time if the env var is not defined #5

@jhrcek

Description

@jhrcek

It would be great if this lib provided a variant of envQ function that would fail at compile time if the environment variable is not defined (i.e. at the time when the TH splice is being evaluated) as opposed to returning Nothing. My use case: I want to hardwire value of environment variable provided at compile time into haskell binary - but don't want to have to deal with Nothing at runtime.
A variant of enQ like this (probably with better name than what I could think of on the spot) could look like this. Would you be willing to add something like this to this library?

envQFailAtCompileTime :: IsString a => String -> SpliceQ a
envQFailAtCompileTime name =
    liftSplice $
        runIO (lookupEnv name) >>= \case
            Just v -> fromCode $ toCode [||fromString v||]
            Nothing -> fail $ "Environment variable " ++ name ++ " not defined"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions