Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,394
    • Issues 4,394
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 373
    • Merge Requests 373
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #8809

Closed
Open
Opened Feb 20, 2014 by joelteon@trac-joelteon

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
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#8809