acton
acton copied to clipboard
Use diagnose library for printing error messages in actonc
diagnose (https://github.com/mesabloo/diagnose) is a Haskell library to print very pretty and helpful error messages. Like this:
We should start using it. Obviously we also have to do lots of heavy lifting to produce good error messages to begin with, but diagnose should definitely help making the output very nice. And we can focus less on rendering and more on the error messages themselves.
It also has some builtin stuff for megaparsec, the parser library we use, so some of our error messages but just might actionable out of the box.
@sydow look at this, so pretty! =)
diagnoseExample errKind f src paths mn ex = do
let e = Err
-- vv OPTIONAL ERROR CODE
Nothing
-- vv ERROR MESSAGE
"Function call error" -- Changed from "Type error" to be more specific
-- vv MARKERS
--[ (Position (4, 5) (4, 9) ((modNameToString mn) ++ ".act"), This "Keyword argument(s) 'y' is not defined in call") ]
--[ (Position (1, 5) (1, 11) ((modNameToString mn) ++ ".act"), Where "Function defined with 2 arguments")
[ (Position (1, 5) (1, 11) ((modNameToString mn) ++ ".act"), Where "Function defined with 2 arguments")
, (Position (4, 5) (4, 9) ((modNameToString mn) ++ ".act"), This "Called without argument 'y'")
]
-- vv HINTS
[ Hint "Add the missing argument: f(3, y_value)" -- Added hint
, Hint "Or provide it as a keyword argument: f(3, y=y_value)"
]
let diag = addFile mempty ((modNameToString mn) ++ ".act") src
diag' = addReport diag e
printDiag diag'
This is done!