Skip to content

Improve error message on wrong indentation of let expression inside do block

Given this code:

    action NewEventAction = do
        now <- getCurrentTime
        let event = newRecord @Event
            |> set #createdAt now -- THIS LINE NEEDS MORE INDENTATION
        render NewView { .. }

GHC errors with:

Admin/Controller/Events.hs:26:9: error:
    The last statement in a 'do' block must be an expression
      let event = newRecord @Event
   |
26 |         let event = newRecord @Event
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

A better error message would be:

Admin/Controller/Events.hs:26:9: error:
    The let-expression is only indented 4 spaces from the do-statement, but it needs to be indented 8 spaces
      '|> set #createdAt now'
   |
26 |         let event = newRecord @Event
27 |             |> set #createdAt now
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

This issue has happend during a twitch livestream of someone building an IHP app for the first time. Here's a link to the video of that livestream: https://youtu.be/Bncy8JiHDYU?t=4939 At 1:22:19 the user get's stuck. It's kind of interesting to watch as you can see how the error message is a bad UX for someone new to haskell :) Hope we can improve this.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information