Glavin001 / atom-beautify

:mega: Help Wanted - Looking for Maintainer: https://github.com/Glavin001/atom-beautify/issues/2572 | :lipstick: Universal beautification package for Atom editor (:warning: Currently migrating to https://github.com/Unibeautify/ and have very limited bandwidth for Atom-Beautify Issues. Thank you for your patience and understanding :heart: )
http://unibeautify.com/
MIT License
1.5k stars 453 forks source link

Invalid Elm code produces odd symbols, and error outside is displayed twice #2005

Closed feature closed 6 years ago

feature commented 6 years ago

Description

When you try to beautify invalid Elm code, the error output will display odd symbols, and the error message is displayed twice, in the same error pane.

Input Before Beautification

import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)

main =
  Html.beginnerProgram { model = model, view = view, update = update }

-- MODEL

type alias Model = Int

model : Model
model =
  0

-- UPDATE

type Msg = Increment | Decrement

update : Msg -> Model -> Model
update msg model =
  case msg of
    Increment ->
      model + 1

    Decrement ->
      model - 1

-- VIEW

view : Model -> 
view model =
  div []
    [ button [ onClick Decrement ] [ text "-" ]
    , div [] [ text (toString model) ]
    , button [ onClick Increment ] [ text "+" ]
    ]

This code is taken from https://guide.elm-lang.org/architecture/user_input/buttons.html I've modified the code, so the view function has an invalid type annotation, to cause the beautification to fail.

Expected Output

I expected the error look something like this (terminal): https://i.imgur.com/OWAtsV8.png

Actual Output

The error dialog displayed by Atom-Beautify: https://i.imgur.com/JrsHlpt.png

Steps to Reproduce

  1. Add invalid Elm code to Atom editor
  2. Run command Atom Beautify: Beautify Editor
  3. The error displays odd symbols, and it's displayed twice

Checklist

I have:

stevenzeck commented 6 years ago

I'll have to look into why we're showing it twice like that, the applicable code is here https://github.com/Glavin001/atom-beautify/blob/master/src/beautify.coffee#L68-L74, where detail is being set to error.message since error.description is undefined in this case.

As for the special characters, @avh4 is it possible to get a "clean" error without the ANSI color codes from the text stream from elm-format?

avh4 commented 6 years ago

So elm-format currently either can format the file or it cannot. If it cannot, then the best way to get the correct syntax error is to run elm-make. (Is it possible that the OP also has a plugin that runs elm-make? In which case, maybe one of the duplicate errors is coming from that plugin.) elm-make has a --report=json flag that can provide a machine-readable version of the syntax error.

elm-format itself doesn't currently have a way to get the errors in another format. I did notice the npm package strip-ansi which might be an easy way to strip that out (and is only about 4 lines of code to copy in if you don't want to add an npm dependency).

Improving the error reporting flexibility of elm-format is low on my priority list, and probably won't happen in the next version unless I get a contributor who wants to focus on that (there's also some prep work that needs to be done before that sort of work could start).

stevenzeck commented 6 years ago

@avh4 Thanks. The duplicate error has nothing to do with elm-format, that's an Atom Beautify thing. I'll look into strip-ansi.

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. If this is still an issue, please add a comment. It will be closed if no further activity occurs. Thank you for your contributions.