-
Notifications
You must be signed in to change notification settings - Fork 65
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
Fails silently with missing file and postcss-import #32
Comments
@timkelty, given this gulpfile: var gulp = require('gulp')
var postcss = require('gulp-postcss')
var postcssImport = require('postcss-import')
gulp.task('default', function () {
return gulp
.src('src/style.css')
.pipe(postcss([postcssImport()]))
.on('error', function (error) {
console.log(error)
})
.pipe(gulp.dest('dest'))
}) and the following css file @import "./missing.css"; I get the following output in the console:
So I guess it is working as expected and the error is passed as a stream event. |
@timkelty got no further input from your side, may I close this? |
I'll test right now and see what's going on with my environment. |
Gulp-postcss (not sure, maybe postcss itself) seem to always fail silently. Any error with missing paths in some of the plugins causes it silently fail. It should print the error, this hardens debugging very much. Issues noticed with |
This is how it looks like: web@web ~/gulp $ npm install gulp-postcss
gulp-postcss@5.1.3 node_modules/gulp-postcss
├── vinyl-sourcemaps-apply@0.1.4 (source-map@0.1.43)
└── gulp-util@3.0.4 (array-differ@1.0.0, object-assign@2.0.0, beeper@1.0.0, array-uniq@1.0.2, lodash._reinterpolate@3.0.0, lodash._reevaluate@3.0.0, lodash._reescape@3.0.0, replace-ext@0.0.1, minimist@1.1.1, chalk@1.0.0, lodash.template@3.5.0, dateformat@1.0.11, multipipe@0.1.2)
web@web ~/gulp $ gulp build:css:next
[14:06:49] Using gulpfile ~/gulp/host/gulpfile.js
[14:06:49] Starting 'build:css:next'...
web@web ~/gulp $ |
Sticking gulp-plumber in the pipe right before postcss takes care of everything for me. @olegstepura I would give that a try if you haven't yet. |
It helps. Thanks! |
gulp-postcss has a test for correct stream error that you can listen to and log to console. It also tests that in case of According to gulp plugin guidelines an error should not be thrown, but it should be emitted. |
Well, stack trace is helpful when you don't know who did thrown an exception. In case of postcss plugins exceptions are no longer thrown by some gulp plugins, it's thrown by postcss plugins that know nothing about gulp. |
@olegstepura of course stack trace is helpful, and it is there for non-cssSyntaxErrors, so feel free to subscribe to the stream error event and use your preferred method of displaying the errors. Tests should give you a hint of how to capture stream errors, or use gulp-plumber with gulp-postcss. |
I'm very exceited of the project This is an offtop, but don't you know if it is possible to tell plumber to print stack? |
Ok, seems the best way is to setup custom error logging function |
@olegstepura feel free to open pull request to improve the quality of certain postcss plugins. This repository is only related to gulp plugin. |
Hoping this is the right place to ask, but what is the best way to surface warnings from postcss plugins now? For example postcss-bem-linter uses the warning class as seen here. But I don't think this triggers an error in a stream? Have tried using postcss-log-warning with Any thoughts? |
@simonsmith I think that warnings should behave differently from the errors, as far as I understand, according to guidelines they should be output in the console rather than emitted as errors. //cc @ai |
I'm also facing this issue, but plumber doesn't seem to be helping: given:gulp.task('styles:toolkit', function () {
var sourcemaps = require('gulp-sourcemaps');
var postcss = require('gulp-postcss');
//var bem_linter = require('postcss-bem-linter');
var calc = require('postcss-calc');
var colorFunction = require('postcss-color-function');
var customMedia = require('postcss-custom-media');
var customProperties = require('postcss-custom-properties');
var fontVariant = require('postcss-font-variant');
var lost = require('lost');
var inline = require('postcss-import');
var nested = require('postcss-nested');
var simpleVars = require('postcss-simple-vars');
var plumber = require('gulp-plumber');
var processors = [
//bem_linter(),
nested,
inline(),
customProperties(),
calc(),
simpleVars(),
customMedia(),
lost(),
colorFunction(),
fontVariant()
];
return gulp.src(config.src.styles.toolkit)
.pipe(sourcemaps.init())
.pipe(plumber())
.pipe(postcss(processors))
.pipe(sourcemaps.write())
.pipe(prefix())
.pipe(gulpif(!config.dev, csso()))
.pipe(gulp.dest(config.dest + '/assets/toolkit/styles'))
.pipe(gulpif(config.dev, reload({stream:true})))
}); running:gulp styles:toolkit --dev resulting:[14:21:19] Using gulpfile ~/projects/LevelEleven/ui-kit/gulpfile.js
[14:21:19] Starting 'styles:toolkit'... |
I also tried using postcss-log-warnings, now I get this: gulp styles:toolkit
[14:41:10] Using gulpfile ~/projects/LevelEleven/ui-kit/gulpfile.js
[14:41:10] Starting 'styles:toolkit'...
** postcss-log-warnings: warnings were found ** but that's it. |
in addition, postcss-import IS finding these files: $> gulp styles:toolkit
[14:58:26] Using gulpfile ~/projects/LevelEleven/ui-kit/gulpfile.js
[14:58:26] Starting 'styles:toolkit'...
[ '/Users/vince/projects/LevelEleven/ui-kit/src/assets/toolkit/styles/toolkit.css',
'/Users/vince/projects/LevelEleven/ui-kit/node_modules/suitcss-components-grid/index.css',
'/Users/vince/projects/LevelEleven/ui-kit/node_modules/suitcss-components-grid/lib/grid.css',
'/Users/vince/projects/LevelEleven/ui-kit/src/assets/toolkit/styles/dude.css' ]
** postcss-log-warnings: warnings were found ** |
@VinSpee sorry, I'm super busy and will only be able to look into this on the weekend. |
No problem! I appreciate you even looking at all. On a second glance, I think the issue may be in gulp-sourcemaps or maybe even gulp-autoprefixer because if I remove them, the build works. I'll close for now. |
@VinSpee that issue is about postcss-log-warnings I believe, not gulp-postcss. See: davidtheclark/postcss-log-warnings#6 --- working on figuring it out. |
@davidtheclark It seems something is indeed wrong in exception handling, problem explained in this gist: https://gist.github.com/w0rm/36ff0b4399a414384690 By default, if there is an unhandled error in the stream, gulp will terminate and output the error in the console, but this is not happening with gulp-postcss. |
My guess is that it has something to do with promises, because an exception that is emitted from the transform function body is output in console, but the one from the postcss promise is not. postcss(processors)
.process(file.contents, opts)
.then(handleResult, handleError) // this error is not in console
handleError(new Error('this error will be output')) |
It should throw an error: postcss/postcss-import#35 (comment)
But when using
gulp-postcss
w/postcss-import
and you try to import a missing file, the gulp task never finishes and postcss processing seems to abort.The text was updated successfully, but these errors were encountered: