Don't wrap Ormolu exceptions as GHC errors

Turns out when ‘--unsafe’ is not set, exceptions thrown in formatting code
are caught in the subsequent parsing check, which wraps them as GHC errors
adding a text like:

  Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Which is misleading since the error is not caused by GHC.

This PR avoids it by strictly binding the result of ‘printModule’.
This commit is contained in:
Utku Demir 2019-09-05 12:51:17 +12:00 committed by Mark Karpov
parent 10232b9c86
commit dde569e918

View File

@ -1,5 +1,6 @@
-- | A formatter for Haskell source code.
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE RecordWildCards #-}
module Ormolu
@ -55,7 +56,12 @@ ormolu cfg path str = do
traceM "warnings:\n"
traceM (concatMap showWarn ws)
traceM (prettyPrintParseResult result0)
let txt = printModule (cfgDebug cfg) result0
-- NOTE We're forcing 'txt' here because otherwise errors (such as
-- messages about not-yet-supported functionality) will be thrown later
-- when we try to parse the rendered code back, inside of GHC monad
-- wrapper which will lead to error messages presenting the exceptions as
-- GHC bugs.
let !txt = printModule (cfgDebug cfg) result0
when (not (cfgUnsafe cfg) || cfgCheckIdempotency cfg) $ do
let pathRendered = path ++ "<rendered>"
-- Parse the result of pretty-printing again and make sure that AST