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

Catch exceptions in message formatting #15

Closed
larsrh opened this issue Oct 27, 2014 · 4 comments · Fixed by #16
Closed

Catch exceptions in message formatting #15

larsrh opened this issue Oct 27, 2014 · 4 comments · Fixed by #16

Comments

@larsrh
Copy link
Contributor

larsrh commented Oct 27, 2014

Same as UnkindPartition/tasty#25. The console reporter deals with it, but not tasty-html.

@larsrh
Copy link
Contributor Author

larsrh commented Oct 27, 2014

Relevant code in tasty: https://github.com/feuerbach/tasty/blob/8eae8007ad60c8ce0041f0976139ed489d367c9c/core/Test/Tasty/Ingredients/ConsoleReporter.hs#L465-L479

-- | Printing exceptions or other messages is tricky — in the process we
-- can get new exceptions!
-- 
-- See e.g. https://github.com/feuerbach/tasty/issues/25
formatMessage :: String -> IO String
formatMessage msg = go 3 msg
where
-- to avoid infinite recursion, we introduce the recursion limit
go :: Int -> String -> IO String
go 0 _ = return "exceptions keep throwing other exceptions!"
go recLimit msg = do
mbStr <- try $ evaluate $ force msg
case mbStr of
Right str -> return str
Left e' -> printf "message threw an exception: %s" <$> go (recLimit-1) (show (e' :: SomeException))

@noschinl
Copy link
Contributor

The commit referenced fixes this issue by copying the formatMessage code from Tasty. One could argue that it would if Tasty exported this function. I'm willing to provide pull requests to implement that.

@UnkindPartition
Copy link
Owner

Sure, I'll export formatMessage later today.

@UnkindPartition
Copy link
Owner

Done, Test.Tasty.Runners.formatMessage is exported by tasty-0.10.1.

noschinl added a commit to larsrh/tasty-html that referenced this issue Oct 27, 2014
noschinl added a commit to larsrh/tasty-html that referenced this issue Oct 27, 2014
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

Successfully merging a pull request may close this issue.

3 participants