This is a program which uses wreq to either request information from a school utility called Ion or sign up for new activities. I feel the error handling is poor and that I've overused the IO Monad. Most of the methods in Lib.hs are impure and I feel this is poor style. Repo. I'd appreciate any feedback on anything from style to overall design. I also know that I'm using partial functions (mostly
head) in Lib.hs which don't always take empty lists and that can lead to exceptions with poor error output and no information for the user and that I need to change that soon.
error-handling example from Main.hs
configPath <- case configFile options of Nothing -> getXdgDirectory XdgConfig "isotope/config" Just a -> return $ fromString a configExists <- doesFileExist configPath unless configExists (throw NoConfigException)
I also feel that the usage of
!! here seems hard-coded and that the return type of string seems like a bad choice but I'm not sure what else to do. Should I have put the output formatting in
signup :: Credentials -> BlockInput -> String -> IO String signup cred blockType activity = do blocks <- fetchBlocks cred let block = case blockType of A -> head blocks B -> blocks !! 1 activities <- fetchBlockActivities cred block let found = findActivityFuzzy activities activity _ <- postWith opts signupUrl ["block" := block_id block, "activity" := aid found] return $ "Signed up for " ++ name found where opts = defaults & auth ?~ basicAuth (cred_un cred) (cred_pass cred)