envy icon indicating copy to clipboard operation
envy copied to clipboard

Poor error messages for bool variables

Open robx opened this issue 2 years ago • 2 comments

Parsing a bool variable, not only does "true" not work as a value, but the error message is not helpful in finding out that I should specify "True":

Parse failure: could not parse variable "TEST_BOOL" into type [Char]

robx avatar Sep 07 '21 09:09 robx

yea, it just uses the Read instance for Bool.

instance Var Bool where toVar = show; fromVar = readMaybe

dmjio avatar Sep 07 '21 16:09 dmjio

You can make your own though.

newtype Thing = Thing Bool
 
instance FromEnv Thing where
  fromEnv _ = fmap Thing $ (True <$ (env "true" <|> env "True")) <|> (False <$ (env "false" <|> env "False"))

dmjio avatar Sep 12 '21 21:09 dmjio