elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.56k stars 662 forks source link

Compiler error produces unexpected output when rendered in a terminal #2302

Open hovsater opened 1 year ago

hovsater commented 1 year ago

Quick Summary:

While working on https://github.com/hovsater/aoc-elm I encountered an error message that produces unexpected output inside a terminal. Specifically the error message seem to emit 65532 spaces in a row as @lydell kindly pointed out in https://github.com/elm/compiler/issues/2302#issuecomment-1502123871. Since the terminal wrap long lines, the result is a very long empty section to scroll through in the middle of the error message.

SSCCE

module Main exposing (main)

failingCode : List () -> List ()
failingCode list =
    case list of
        [ a, a ] -> list
        _ -> list

Additional Details

The problem can be produced when running with the JSON reporter as well (i.e., --report=json).

Here's the raw output from the terminal (produced by running script /tmp/output and then running /tmp/output through sed -n 'l' ```console Script started on Mon Apr 10 17:12:41 2023$ \033[?2004h~/code/elm-bug $ elm make --output=/dev/null src\ /Main.elm\r$ \033[?2004l\rCompiling ...\rDetected problems in 1 module.\ \r$ \033[36m-- NAME CLASH -------------------------------------\ ---------------- src/Main.elm\033[0m\r$ \r$ This `case` pattern has multiple `a` variables.\r$ \r$ 6| [ a, a ] -> list\r$ \033[91m^\033[0m \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \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\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \033[91m^\033[0m\r$ How can I know which one you want? Rename one of them!\r$ \r$ \033[?2004h~/code/elm-bug $ \033[?2004l\r\r$ exit\r$ $ Script done on Mon Apr 10 17:12:51 2023$ ```
github-actions[bot] commented 1 year ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.

lydell commented 1 year ago

As far as I can tell, “breaks terminal rendering” is a bit of a red herring. What seems to happen is that line 6 of the error message contains 65532 spaces in a row. Terminals wrap long lines, which in effect results in a very long empty section to scroll through in the middle of the error message.

Here I replaced long sequences of a character like XXXXXXX… with {X}*42:

❯ elm make Main.elm 2> output.txt
Detected problems in 1 module.

❯ node -p 'fs.readFileSync("output.txt", "utf8").replace(/(.)\\1{5,}/g, m => `{${m[0]}}*${m.length}`)'
-- NAME CLASH {-}*57 Main.elm

This `case` pattern has multiple `a` variables.

6|{ }*9[ a, a ] -> list
{ }*16^{ }*65532^
How can I know which one you want? Rename one of them!

Random note: 65532 is suspiciously close to 2^16 = 65,536.

hovsater commented 1 year ago

As far as I can tell, “breaks terminal rendering” is a bit of a red herring.

You're right. That was probably some unfortunate wording on my part. I've updated the description accordingly. 🙂