Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 5.5k
    • Issues 5.5k
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 631
    • Merge requests 631
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Model experiments
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #8809

Prettier error messages?

PrettyErrors is a wiki page summarising the state of play.

clang has very nice-looking error messages.

<pre><span style="font-weight: bold">pretty.c:6:7: <span style="color: pink">warning:</span> incompatible pointer to integer conversion passing 'char [14]' to parameter of type 'int' [-Wint-conversion]</span>
  foo("Hello, world!");
      <span style="color: green">^~~~~~~~~~~~~~~</span>
<span style="font-weight: bold">pretty.c:1:14: note: passing argument to parameter 'i' here</span>
void foo(int i) {
             <span style="color: green">^</span>
1 warning generated.</pre>

ghc's error messages are not so good.

<pre>ugly.hs:7:18:
    Couldn't match expected type &lsquo;()&rsquo; with actual type &lsquo;[Char]&rsquo;
    In the first argument of &lsquo;f&rsquo;, namely &lsquo;"Hello, world!"&rsquo;
    In the second argument of &lsquo;($)&rsquo;, namely &lsquo;f "Hello, world!"&rsquo;
    In the expression: print $ f "Hello, world!"</pre>

In my opinion, there are three independent improvements that could be made to GHC error messages and warnings: color, context and whitespace. Currently they're blobs of text.

Consider all three applied to error messages:

<pre><strong>ugly.hs:7:18: <span style="color: red">error:</span> Argument to 'f' is type '[Char]' but expected 'Int'</strong>
main = print $ f "Hello, world!"
                 <span style="color: green">^~~~~~~~~~~~~~~</span>

<strong>ugly.hs:3:1: note: type of 'f' is given here:</strong>
f :: () -> IO ()
     <span style="color: green">^~</span></pre>

or

ugly.hs: note: type of 'f' is inferred: f :: forall m. Monad m => () -> m () ^~

In my opinion, context and whitespace are more important that color. Even without color, compare this error message to the one shown above:

ugly.hs:7:18: error: Argument to 'f' is type '[Char]' but expected 'Int'
main = print $ f "Hello, world!"
                 ^~~~~~~~~~~~~~~

ugly.hs:3:1: note: type of 'f' is given here:
f :: () -> IO ()
     ^~

In my opinion this is much easier to visually process than GHC's current messages.

Edited Mar 23, 2021 by Sylvain Henry
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking