-try_m :: TcRn r -> TcRn (Either Exception r)
--- Does try_m, with a debug-trace on failure
-try_m thing
- = do { mb_r <- tryM thing ;
- case mb_r of
- Left exn -> do { traceTc (exn_msg exn); return mb_r }
- Right r -> return mb_r }
- where
- exn_msg exn = text "tryTc/recoverM recovering from" <+> text (showException exn)
+-----------------------
+tryTcErrs :: TcRn a -> TcRn (Messages, Maybe a)
+-- Run the thing, returning
+-- Just r, if m succceeds with no error messages
+-- Nothing, if m fails, or if it succeeds but has error messages
+-- Either way, the messages are returned; even in the Just case
+-- there might be warnings
+tryTcErrs thing
+ = do { (msgs, res) <- tryTc thing
+ ; dflags <- getDOpts
+ ; let errs_found = errorsFound dflags msgs
+ ; return (msgs, case res of
+ Nothing -> Nothing
+ Just val | errs_found -> Nothing
+ | otherwise -> Just val)
+ }