Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocTests in src/Level06/Conf/File.hs are out of date #80

Closed
ScottSedgwick opened this issue Jun 25, 2019 · 1 comment
Closed

DocTests in src/Level06/Conf/File.hs are out of date #80

ScottSedgwick opened this issue Jun 25, 2019 · 1 comment

Comments

@ScottSedgwick
Copy link

In src/Level06/Conf/File.hs:
Change

import           Level06.AppM               (AppM)

to

import           Level06.AppM               (AppM(runAppM))

and change

-- >>> 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"
@mankyKitty
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants