binary
binary copied to clipboard
Export failG
99% of the time, I see developers trying to use fail to throw an error in the same way error does, but fail means "early termination of a monad", not necessarily throwing an error (e.g. fail _ = [] in the list monad). In some cases, this can create bugs (in our case, a developer accidentally changed the monad from a ReaderT IO stack to the list monad, which started silently returning empty lists instead of failing), so I'd like to ban the use of fail in our codebase with HLint.
Most of the cases I found were easy to replace: Data.Aeson.Types.parseFail, Tasty.HUnit.assertFailure, or just plain dropping in error. But the one location that isn't currently easily replaceable is using fail in the Get monad from Data.Binary. For now, I can workaround this with
{- HLint ignore "Avoid fail" -}
failGet :: String -> Get a
failGet = fail
but it would be great to export failG from Data.Binary.Get.Internal (preferably in Data.Binary.Get with a better name like failGet).