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
fix(site-playground): add missing error handling to fix WSOD (#991) #1154
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1154 +/- ##
=======================================
Coverage 96.43% 96.43%
=======================================
Files 116 116
Lines 3592 3592
Branches 1054 1054
=======================================
Hits 3464 3464
Misses 119 119
Partials 9 9 Continue to review full report at Codecov.
|
In case anyone would be curious, the rationale for choosing this error format is: From the Which looks like this:
While in the
But... here we do have access to the different parts as properties of the error: So the easiest way to get them to conform to a common format, without too much fiddly and unnecessary processing, was to simply discard anything after the first line on the errors from Prettier and format the The line/column number is anyway available in the error, and the editor itself also attempts to highlight. So discarding the verbose output with the line/column indicator doesn't really lose any valuable information. Keeping the message consistent and concise seems more important, considering the location it's displayed. |
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.
/cc @ludofischer
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.
LGTM
padding: 0.3em 1em; | ||
} | ||
|
||
.inputError[data-theme='light'] { |
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.
Nice touch!
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.
Thanks :)
This pull request aims to fix the playground WSOD reported in #991
I found two related issues leading to this behaviour:
prettier.format()
when the "Format" button is used.setOutput()
in order to output it to the output pane of the playground. Here it was passed in raw asEditorProps.value
- which expected a string, not an object.The two cases throws slightly different types of errors.
On most syntax errors, Prettier throws a
SyntaxError
wrapping some output fromCssSyntaxError
thrown by the css parser - which is quite verbose with numbered line output and such in the message. There are also some edge cases causing Prettier to throw different types of errors. And the line numbering from the SyntaxError does not correspond to the input lines.While postcss throws a clean
CssSyntaxError
with good/usable information.I therefore introduced a simple error handling function which conforms the errors to a short and concise format (using common factors), and outputs it as a red bar right above the code panes. So now the error will for the most part be identical whether one clicks "Run" or "Format"
This is also more friendly for devices with small screen resolutions, where outputting errors to the output pane would be out of view and could cause confusion (i.e. "nothing happening" when clicking the buttons)
I tried to follow the general style/conventions of the existing code.
Closes #991