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
Improve elm compiler error output #7994
Improve elm compiler error output #7994
Conversation
Get as close as possible to the original Elm compiler output and how Parcel v1 displayed the errors: - add some useful formatting - disable the stack track (not useful when developing) - convert structured elm errors report into Parcel's diabnostics structure - preserve indentation in lines where parcel removes spaces (by using > as first char, it's a workaround but better than no indentation)
Ideally we could extract the file/line/column/message parts and then create a diagnostic codeframe, but that's probably not exposed separately in the error object. |
@mischnic Thanks for checking. Short answerThe elm compiler error does provide file/line/column info but the problem is that the message contains code/hint parts with no way to extract them in a way that makes sense. Generally the error structure of Elm does not map very well to the Parcel diagnostic structure, that's why I only tried to improve the way it is displayed as a Would leaving it this way be ok or is there another way to make it work? Any input is appreciated. Long answerI attempted to get it to work, but as far as I'm concerned I couldn't get converted in a meaningful way. Here's an example for two errors: Here's the JSON version for this message. As you can see the `message` is simply an array of pieces with info what the **hint** or the **code** is. Click here ...The interesting part is at {
"type": "compile-errors",
"errors": [
{
"path": "/Users/d441365/projects/test/src/Main.elm",
"name": "Main",
"problems": [
{
"title": "MISSING PATTERNS",
"region": {
"start": {
"line": 26,
"column": 5
},
"end": {
"line": 31,
"column": 48
}
},
"message": [
"This `case` does not have branches for all possibilities:\n\n26|",
{
"bold": false,
"underline": false,
"color": "RED",
"string": ">"
},
" case msg of\n27|",
{
"bold": false,
"underline": false,
"color": "RED",
"string": ">"
},
" Increment ->\n28|",
{
"bold": false,
"underline": false,
"color": "RED",
"string": ">"
},
" { model | count = model.count + 1 }\n29|",
{
"bold": false,
"underline": false,
"color": "RED",
"string": ">"
},
"\n30|",
{
"bold": false,
"underline": false,
"color": "RED",
"string": ">"
},
" Decrement ->\n31|",
{
"bold": false,
"underline": false,
"color": "RED",
"string": ">"
},
" { model | count = model.count - 1 }\n\nMissing possibilities include:\n\n ",
{
"bold": false,
"underline": false,
"color": "yellow",
"string": "Peter"
},
"\n\nI would have to crash if I saw one of those. Add branches for them!\n\n",
{
"bold": false,
"underline": true,
"color": null,
"string": "Hint"
},
": If you want to write the code for each branch later, use `Debug.todo` as a\nplaceholder. Read <https://elm-lang.org/0.19.1/missing-patterns> for more\nguidance on this workflow."
]
},
{
"title": "MISSING PATTERNS",
"region": {
"start": {
"line": 34,
"column": 5
},
"end": {
"line": 36,
"column": 29
}
},
"message": [
"This `case` does not have branches for all possibilities:\n\n34|",
{
"bold": false,
"underline": false,
"color": "RED",
"string": ">"
},
" case msg of\n35|",
{
"bold": false,
"underline": false,
"color": "RED",
"string": ">"
},
" Increment -> \"Assi\"\n36|",
{
"bold": false,
"underline": false,
"color": "RED",
"string": ">"
},
" Decrement -> \"Peter\"\n\nMissing possibilities include:\n\n ",
{
"bold": false,
"underline": false,
"color": "yellow",
"string": "Peter"
},
"\n\nI would have to crash if I saw one of those. Add branches for them!\n\n",
{
"bold": false,
"underline": true,
"color": null,
"string": "Hint"
},
": If you want to write the code for each branch later, use `Debug.todo` as a\nplaceholder. Read <https://elm-lang.org/0.19.1/missing-patterns> for more\nguidance on this workflow."
]
}
]
}
]
} As you can see the message is basically a sentence that uses code snippets sometimes in the middle of a sentence. On a high level the parcel diagnostic contains
The Elm error output contains (per problem)
Since there is no structural information to separate the hint and the code frame from the message, and the fact that the message already contains both in a meaningful way, makes it hard to map to parcel's model, so I'm suggesting to leave it at that. For reference:This merged PR also decided to leave the message as a string after stuggling with mapping it to a diagnostic.
|
Yeah, putting this into the message instead of the stack is definitely an improvement over the current situation. Please remove the example and create a test case similar to one of these (so also create a folder next to
Then you can assert the diagnostic like this
That leading space removal comes from this
This could be fixed by changing it to this to only trim trailing spaces function wrapWithIndent(string, indent = 0, initialIndent = indent) {
let width = getTerminalWidth().columns;
return indentString(
wrapAnsi(string.trimEnd(), width - indent, {trim: false}),
indent,
initialIndent,
);
}
Yes, let's do that. |
@mischnic great, I will provide the changes you asked for. |
…mpiler-error-output
…ces, leave leading ones untouched
…ophP/parcel into improve-elm-compiler-error-output
@mischnic Made all the changes
Now the output looks nice. Terminal:Browser: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok to me. Might be nice to try to map these to Parcel diagnostics if we can figure out how at some point, but this is an improvement.
Nice, thanks for reviewing. |
Mostly that's on us because Some tests are flakey (and we'll take care of that).
You'll have to do wrap the parcel/packages/core/integration-tests/test/scope-hoisting.js Lines 559 to 562 in 4e40429
|
bec8033
to
35e4785
Compare
🙌 |
↪️ Pull Request
Fixes #7957
This PR adds changes to the
transformer-elm
that makes compiler output look more like they used to in Parcel v1.The way it is currently is hard to read in many terminals with a dark background.
💻 Examples
This implements to following change, when any compilation error happens for Elm code. The output is more readable because it is logged as in the
message
of the diagnostic instead of thestack
part.Before:
After:
🚨 Test instructions
This PR also adds an entry in the
packages/examples
for folder elm for testing. It was useful for me and I thought that was the way to go from reading theContributing.md
file. If that example is not useful to anyone but me I can remove it from this PR if anyone lets me know.Testable this way:
packages/examples/elm
yarn install
src/Main.elm
until the error output appears in the console.yarn demo
✔️ Bonus
While this change improves the error output in the terminal, it kind of messes up the one in the browser.
With this change:
Before this change (correctly formatted but hard to read if background is dark also a gray tone):
This is due to the browser display not respecting white space for formatting.
Would it be possible to add
white-space: pre;
to the.error-message
class? It seems that whitespace is preserved when logging things asstack
(but hard to read on dark background) but not for themessage
part of a throwable diagnostic. I think it would make sense to add this because otherwise you get things that look differently in the terminal and in the browser.