Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--report=json emits a non-JSON nicely formatted error #2264

Open
Janiczek opened this issue Jun 22, 2022 · 6 comments
Open

--report=json emits a non-JSON nicely formatted error #2264

Janiczek opened this issue Jun 22, 2022 · 6 comments

Comments

@Janiczek
Copy link

Janiczek commented Jun 22, 2022

Quick Summary: elm make --report=json sometimes emits errors in a non-JSON format, breaking tools like @parcel/transformer-elm: (EDIT: they pick a second line and JSON.parse it)

Compilation failed
 -------------------------------------------------------------------------------
|  Corrupt File: /home/runner/work/frontend-gcp/frontend-gcp/elm/elm-stuff/0.19.1/i.dat
|   Byte Offset: 1183122
|       Message: not enough bytes
|
| Please report this to https://github.com/elm/compiler/issues
| Trying to continue anyway.
 -------------------------------------------------------------------------------
{"type":"error","path":null,"title":"CORRUPT CACHE","message":["It looks like some of the information cached in elm-stuff/ has been corrupted.\nTry deleting your elm-stuff/ directory to get unstuck.\n\n",{"bold":false,"underline":true,"color":null,"string":"Note"},": This almost certainly means that a 3rd party tool (or editor plugin) is\ncausing problems your the elm-stuff/ directory. Try disabling 3rd party tools\none by one until you figure out which it is!"]}
  • Elm: 0.19.1
  • Browser: N/A
  • Operating System: Linux (GitHub Actions CI)
@github-actions
Copy link

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions in a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

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

@ChristophP
Copy link

Are your sure both of those messages (the readable part and the JSON) are written to the same output stream?
Usually the message part could be written to stdout while the json part is written to stderr (or vice versa).

@lydell
Copy link
Contributor

lydell commented Jun 23, 2022

Yes, both are written to stderr:

~/stuff
❯ mkdir  elm-error

~/stuff
❯ cd elm-error

~/stuff/elm-error
❯ yes | elm init >/dev/null

~/stuff/elm-error
❯ printf 'module Dummy exposing (dummy)\ndummy = ()' > src/Dummy.elm

~/stuff/elm-error
❯ elm make --report=json src/Dummy.elm

~/stuff/elm-error
❯ truncate -s 1024 elm-stuff/0.19.1/i.dat

~/stuff/elm-error
❯ elm make --report=json src/Dummy.elm > stdout.txt 2> stderr.txt

~/stuff/elm-error
❯ bat stdout.txt stderr.txt
───────┬─────────────────────────────────────────────────────────────────────────────────
       │ File: stdout.txt   <EMPTY>
       │ Size: 0 B
───────┴─────────────────────────────────────────────────────────────────────────────────
───────┬─────────────────────────────────────────────────────────────────────────────────
       │ File: stderr.txt
       │ Size: 852 B
───────┼─────────────────────────────────────────────────────────────────────────────────
   1   │  -------------------------------------------------------------------------------
   2   │ |  Corrupt File: /Users/lydell/stuff/elm-error/elm-stuff/0.19.1/i.dat
   3   │ |   Byte Offset: 1024
   4   │ |       Message: not enough bytes
   5   │ |
   6   │ | Please report this to https://github.com/elm/compiler/issues
   7   │ | Trying to continue anyway.
   8   │  -------------------------------------------------------------------------------
   9   │
  10   │ {"type":"error","path":null,"title":"CORRUPT CACHE","message":["It looks like some of the information cached in elm-stuff/ has been corrupted.\n\nTry deleting your elm
       │ -stuff/ directory to get unstuck.\n\n",{"bold":false,"underline":true,"color":null,"string":"Note"},": This almost certainly means that a 3rd party tool (or editor plu
       │ gin) is\ncausing problems your the elm-stuff/ directory. Try disabling 3rd party tools\none by one until you figure out which it is!"]}
───────┴─────────────────────────────────────────────────────────────────────────────────

In my experience, this happens whenever elm prints one of those “boxes”:

 ---------------
| something
 ---------------

@ChristophP
Copy link

Ah, I see 😢

lydell added a commit to lydell/elm-watch that referenced this issue Jun 23, 2022
@unsafe-andrew-old
Copy link

So what is a proposed solution? Print the error in the json format to the stdout? Or somehow remove those additional messages? The first one is solveable in changing literally 3 symbols in the source code

@Janiczek
Copy link
Author

I imagine if --report=json is active, all the output should be those JSON lines. The -boxed message shouldn't be shown.

An alternative is to send some of it to stdout and some of it to stderr, so that one of the streams still is purely JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants