You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- >>> readConfFile "badFileName.no"
-- Left (undefined "badFileName.no: openBinaryFile: does not exist (No such file or directory)")
-- >>> readConfFile "files/test.json"
-- Right "{\n \"foo\": 33\n}\n"
to
-- >>> runAppM $ readConfFile "badFileName.no"
-- *** Exception: badFileName.no: openBinaryFile: does not exist (No such file or directory)
-- >>> runAppM $ readConfFile "files/test.json"
-- Right "{\"foo\":33}\n"
The text was updated successfully, but these errors were encountered:
Adding runAppM is correct. However you've updated the test to suit what your code was doing, not what the test is trying to check for, which is not correct.
The expectation is that you implement the readConfFile function so when you runAppM the value that is returned is Right when you successfully read the file, or Left with reason that reading the file failed. Using the try function or something else from Control.Exception we're able to execute functions and not let exceptions escape.
This will require that you be explicit about what type of exception you're going to want to catch. Since we're reading a file, the choice of IOException is the most appropriate. Since things like ArithException and AsyncException don't make much sense in this context.
The undefined can then be updated to be the constructor from ConfigError that you create to wrap the exception. Using show on the exception is sufficient for this exercise.
In
src/Level06/Conf/File.hs
:Change
to
and change
to
The text was updated successfully, but these errors were encountered: