-
Notifications
You must be signed in to change notification settings - Fork 12k
Log gulp error to Chart.js #5143
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
Conversation
+ Add intentional error to core to check if travis fails
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.
Can you post part of the log of the error before and after this change?
gulpfile.js
Outdated
| .on('error', function (err) { | ||
| util.log(util.colors.red('[Error]'), err.toString()) | ||
| fs.writeFileSync(outDir+'Chart.bundle.js', 'console.error("Gulp: ' + err.toString() + '")'); | ||
| fs.writeFileSync(outDir+'Chart.bundle.min.js', 'console.error("Gulp: ' + err.toString() + '")'); |
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.
I would not alter Chart.bundle(.min)?.js, simply log the error to console.
gulpfile.js
Outdated
| .ignore('moment') | ||
| .plugin(collapse) | ||
| .bundle() | ||
| .on('error', function (err) { |
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.
Can we avoid code duplication by refactoring this method:
var errorHandler = function (err) {
util.log(util.colors.red('[Error]'), err.toString());
this.emit('end');
}
// ...
.bundle()
.on('error', errorHandler)
// ...
.on('error', errorHandler)|
I added the logs in the top comment |
|
I'm reading again your description: does that mean the gulp build process doesn't fail anymore in case of parsing errors? |
gulpfile.js
Outdated
| fs.writeFileSync(outDir+'Chart.js', browserError); | ||
| fs.writeFileSync(outDir+'Chart.min.js', browserError); | ||
| fs.writeFileSync(outDir+'Chart.bundle.js', browserError); | ||
| fs.writeFileSync(outDir+'Chart.bundle.min.js', browserError); |
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.
@simonbrunel if possible, i would like to be able to see the errors directly in the browser. I prefer to work in the editor and the browser only, and not have to check the terminal.
|
Yes, gulp continues to run. |
|
Maybe the travis log could be helpful https://travis-ci.org/chartjs/Chart.js/builds/328424793 |
|
These changes are not safe: first the I'm not fan of the
Indeed, the Travis build fails, but that's not controlled, which is a door open on more issues. |
|
Though, I plan to refactor the gulp file for a better |
|
I followed your advice and used options. |
simonbrunel
left a comment
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.
We can keep --silent-errors for now.
I don't think I would update contributing.md right now because with the number of options increasing, it will be complicated to maintain. Instead, we will use the yargs help method (gulp --help), which is planned in the upcoming refactor and thus another PR.
gulpfile.js
Outdated
| " * https://github.com/chartjs/Chart.js/blob/master/LICENSE.md\n" + | ||
| " */\n"; | ||
|
|
||
| var options = minimist(process.argv.slice(2)); |
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.
We already depend on yargs, no need for minimist:
var argv = require('yargs')
.option('force-output', {default: 'false'})
.option('silent-errors', {default: 'false'})
.option('verbose', {default: 'false'})
.argv;
// ...
if (argv.forceOutput) { ... }
if (argv.silentErrors) { ... }
gulpfile.js
Outdated
| // compare to what the current codebase can support, and since it's not straightforward | ||
| // to fix, let's turn them as warnings and rewrite code later progressively. | ||
| var options = { | ||
| var eslintOptions = { |
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.
No need to rename this variable, we can keep var argv = ...
| var argv = require('yargs').argv | ||
| var path = require('path'); | ||
| var package = require('./package.json'); | ||
| var fs = require('fs'); |
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.
[nit] can we move var fs before var package since the later one is a local file.
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.
yes
while i'm at it, is there any logic in the order for the non local dependencies ? alphabetical, date of addition ?
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.
No guideline for the order because some require() may need other ones. I'm used to gather related dependencies (e.g. gulp-*) and declare the package.json at the end.
gulpfile.js
Outdated
| function buildTask() { | ||
|
|
||
| var errorHandler = function (err) { | ||
| util.log(util.colors.red('[Error]'), err.toString()); |
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.
I would move that line before this.emit('end');, it's only useful when ignoring exceptions
gulpfile.js
Outdated
| " */\n"; | ||
|
|
||
| var options = minimist(process.argv.slice(2)); | ||
| util.log("Gulp running with options: "+JSON.stringify(options, null, 2)); |
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.
if (argv.verbose) {
util.log("Gulp running with options: " + JSON.stringify(argv, null, 2));
}
gulpfile.js
Outdated
| var merge = require('merge-stream'); | ||
| var collapse = require('bundle-collapser/plugin'); | ||
| var argv = require('yargs').argv | ||
| var argv = require('yargs') |
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.
Though, since this one will grow, I would keep it outside the others for a better readability of dependencies :)
Maybe:
var collapse = require('bundle-collapser/plugin');
var yargs = require('yargs');
var path = require('path');
var package = require('./package.json');
var argv = yargs
.option('force-output', {default: 'false'})
// ..
.argv;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.
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.
but I think I prefer the first solution: var yargs = require('yargs');
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.
Yes, I think it makes more sense to keep all the dependencies small and together.
gulpfile.js
Outdated
| var package = require('./package.json'); | ||
|
|
||
| var argv = yargs | ||
| .option('force-output', {default: 'false'}) |
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.
My bad, I think it should be {default: false} (boolean instead of string)
simonbrunel
left a comment
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 @loicbourgois (and sorry for all these iterations)
* Log errors and skip for buildTask * Write gulp error to Chart.js + Add intentional error to core to check if travis fails * Remove unused require * Remove error + Proper require fs * Fix newline * Refactor * Put back browser errors * Use options * Fix intentional error * Use yargs + Refactor * remove space * Fefactor * Use booleans
If gulp encounters an error when building, it just stops, which means the
Chart.jsfiles are not updated with the error, and that gulp would have to be restarted manually.This PR takes care of it.
Gulp log before
Gulp log after
It's possible to have the full trace using simply
util.log(err)