Skip to content

Commit

Permalink
Improve display of interpreter errors (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
patritzenfeld authored Oct 9, 2024
1 parent d22091e commit f8aaa91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fmap
foldl
foldr
fst
ghc
GHC
github
Graphviz
Expand Down
16 changes: 14 additions & 2 deletions flex-task/src/FlexTask/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The interpreted code is usually supplied by accessing data stored in `FlexInst`
module FlexTask.Interpreter
( checkSolution
, genFlexInst
, prettyError
, runWithPackageDB
, validDescription
) where
Expand All @@ -26,8 +27,9 @@ import Data.Text.Lazy.Encoding (encodeUtf8)
import Data.Text.Lazy (pack)
import Data.Typeable (Typeable)
import Language.Haskell.Interpreter (
GhcError(errMsg),
Interpreter,
InterpreterError,
InterpreterError(..),
infer,
interpret,
loadModules,
Expand Down Expand Up @@ -262,7 +264,7 @@ writeUncachedAndGetPaths xs = do


extract :: Either InterpreterError c -> c
extract = either (error . show) id
extract = either (error . prettyError) id


hash :: Show a => a -> String
Expand Down Expand Up @@ -294,3 +296,13 @@ imageLinks = concatMap gatherLinks
gatherLinks (Itemized oss) = imageLinks $ concat oss
gatherLinks (Indented os) = imageLinks os
gatherLinks _ = []


{- |
Custom display of Hint InterpreterError messages.
-}
prettyError :: InterpreterError -> String
prettyError (UnknownError s) = "Unknown error:\n" ++ s
prettyError (NotAllowed s) = "Not allowed:\n" ++ s
prettyError (GhcException s) = "GHC exception occurred:\n" ++ s
prettyError (WontCompile ghcErrors) = "Won't compile:\n" ++ unlines (map errMsg ghcErrors)

0 comments on commit f8aaa91

Please sign in to comment.