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

Syntax error formatting in the console #264

Closed
robcrocombe opened this issue Jan 16, 2017 · 6 comments
Closed

Syntax error formatting in the console #264

robcrocombe opened this issue Jan 16, 2017 · 6 comments

Comments

@robcrocombe
Copy link

Hi, I'm using this plugin in Gulp. When there is an error in the main file (not imported) it displays in a code frame like this:

  11 | */
  12 |
> 13 | a {
     | ^
  14 |   color: red;
  15 |

However, if the error is from an imported file I get this (for example):

postcss-import: /Users/.../stylesheets/app.css:1:1: /Users/.../stylesheets/src/base.css:54:1: Unclosed block

Is there a way I can get the pretty-printed error message instead? Thanks

@RyanZim
Copy link
Collaborator

RyanZim commented Jan 16, 2017

Not sure.

@ai We are currently sending errors back via result.warn() https://github.com/postcss/postcss-import/blob/master/index.js#L282. Do you know offhand if there is a better way to do this?

@michael-ciniawsky
Copy link

if (err.name === 'CssSyntaxError') err.message + '\n\n' + err.showSourceCode() + '\n'

or don't add it to result.warn and pass it through. gulp-postcss joins and logs warnings with gutil. That's also the reason while the file path is displayed twice in the example above. gulp-postcss would handle the err like the code above does.

@RyanZim
Copy link
Collaborator

RyanZim commented Jan 16, 2017

@michael-ciniawsky Thanks for chiming in, I knew there was probably a better way, but didn't have time to look.

I would consider erroring for syntax errors in the next major release; for now, we need to still warn to keep backwards compatibility.

PR welcome to add err.showSourceCode() to the error message.

@ai
Copy link
Member

ai commented Jan 16, 2017

@RyanZim result.warn() is for warnings. It is better to throw correct a SyntaxError (it is a little bit tricky to build correct one, but you will have this cute code example)

@RyanZim
Copy link
Collaborator

RyanZim commented Jan 16, 2017

@ai I will definitely throw an error in the next major, but I thought changing the result.warn behavior would be a breaking change.

@RyanZim RyanZim added this to the 11.0.0 milestone Aug 24, 2017
@robcrocombe
Copy link
Author

@RyanZim I take it it's been resolved. Thanks!

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

No branches or pull requests

4 participants