elm / error-message-catalog

A catalog of broken Elm programs / data to improve error messages
BSD 3-Clause "New" or "Revised" License
174 stars 17 forks source link

Add line number next to File path separated by a ":" #313

Open girishso opened 4 years ago

girishso commented 4 years ago

This is a standard followed by Go, Ruby, Elixir and many others, allows Command+Click in iTerm to directly open the file and jump to erroring line. A huge time saver.

To be specific

-- TYPE MISMATCH -------------------------------------------------- src/Main.elm

Something is off with the 2nd branch of this `if` expression:

746|                 messages err
                     ^^^^^^^^^^^^
This `messages` call produces:

    List Msg

But the type annotation on `messagesHelper` says it should be:

    Msg

First line should become

-- TYPE MISMATCH -------------------------------------------------- src/Main.elm:746
evancz commented 4 years ago

The compiler has a --report=json flag that gives all the region information in a structured format. This is intended to be used by people making editor plugins so that they can do the particular editor integration that makes sense for their editor.

How many terminals have this "open file at certain line" feature? (I.e. would this work for the default terminal on macOS, Windows, or Ubuntu?)

girishso commented 4 years ago

I only have access to a Mac, the default Terminal app doesn't seem to have this feature, only iTerm.

For the sake of completeness, this is how different languages display errors.

Ruby

$ ruby main.rb                                            
Traceback (most recent call last):
    5: from main.rb:5:in `<main>'

Elixir

==> postgrex
Compiling 62 files (.ex)
warning: Enum.partition/2 is deprecated. Use Enum.split_with/2 instead
  lib/postgrex/error_code.ex:14

Go

go run main.go                     
# command-line-arguments
./main.go:43:13: undefined: Hasher
./main.go:45:12: undefined: CmdHasher
./main.go:47:12: undefined: DefaultHasher