acton icon indicating copy to clipboard operation
acton copied to clipboard

Use diagnose library for printing error messages in actonc

Open plajjan opened this issue 1 year ago • 1 comments

diagnose (https://github.com/mesabloo/diagnose) is a Haskell library to print very pretty and helpful error messages. Like this: image

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.

plajjan avatar Jul 15 '24 18:07 plajjan

@sydow look at this, so pretty! =)

plajjan avatar Jul 15 '24 22:07 plajjan

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'

plajjan avatar Jan 15 '25 08:01 plajjan

This is done!

plajjan avatar Apr 03 '25 19:04 plajjan