Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Avoid empty error messages #6

Closed

Conversation

pelotom
Copy link

@pelotom pelotom commented Jul 5, 2014

This fixes a problem where psc and docgen throw errors while throwing errors. That is, if a compilation error occurs during psc for example, we emit an error using new gutil.PluginError(PLUGIN, buffer.toString()), but buffer.toString() is null, so we get this error:

Error: Missing error message
    at new PluginError (/Users/tom/code/purescript-d3-examples/node_modules/gulp-purescript/node_modules/gulp-util/lib/PluginError.js:53:28)
    at ChildProcess.<anonymous> (/Users/tom/code/purescript-d3-examples/node_modules/gulp-purescript/index.js:94:38)
    at ChildProcess.emit (events.js:98:17)
    at maybeClose (child_process.js:755:16)
    at Socket.<anonymous> (child_process.js:968:11)
    at Socket.emit (events.js:95:17)
    at Pipe.close (net.js:465:12)

which can't be handled and causes gulp to exit. This is especially annoying when trying to use gulp watch.

The fix makes psc and docgen do the same thing as pscMake; that is, give a static failure message.

@@ -91,7 +91,7 @@ function psc(opts) {
gutil.log('Stderr from \'' + gutil.colors.cyan('psc') + '\'\n' + gutil.colors.magenta(stderr));
});
cmd.on('close', function(code){
if (!!code) that.emit('error', new gutil.PluginError(PLUGIN, buffer.toString()));
if (!!code) that.emit('error', new gutil.PluginError(PLUGIN, "psc has failed"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth doing these as buffer.toString() || "psc has failed"? Or is the buffer always empty in this case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garyb I agree. I think we want to keep the buffer's value in these cases. Maybe we should go with your suggestion. Does this work for you @pelotom?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my experience it is always empty, but I'm certainly not opposed to showing it if there's ever something there.

ethul added a commit that referenced this pull request Jul 5, 2014
Errors during compilation are now captured on stderr instead of stdout.
This resolves issue #6, where gulp-util was throwing an exception due to
a missing error message.
@ethul
Copy link
Contributor

ethul commented Jul 5, 2014

@pelotom, can you please try out version 0.0.9? I think the issue was that the plugin needed to capture the buffer on stderr instead of stdout. I think in the newer version of purescript, the compiler error is no longer written to stdout, which resulted in the error you saw. I made the change and published it as 0.0.9. If this does not work for you, maybe we can look at this again and revisit this PR. Thanks for tracking down this issue!

@ethul ethul closed this Jul 5, 2014
@pelotom
Copy link
Author

pelotom commented Jul 5, 2014

That works great, but shouldn't pscMake do the same? It's still spitting out a constant message 'psc-make has failed'.

@ethul
Copy link
Contributor

ethul commented Jul 5, 2014

Great, glad it works!

Regarding pscMake, that command actually works a little different. It does not do any streaming of files, it just outputs them to the filesystem directly. Since there is no buffer to collect on stdout, I just logged the error message on stderr, just like the stdout behaviour. I'd be open to collecting stderr in a buffer, but I could go either way.

@pelotom
Copy link
Author

pelotom commented Jul 5, 2014

I think still collecting the stderr output and logging that when an error happens is better behavior. For one thing, stderr gets interleaved nondeterministically with other gulp output, so you get stuff like this:

[14:27:20] Stderr from 'psc'
"/Users/tom/code/pure
[14:27:20] Stderr from 'psc'
script-d3-examples/src/LetsMakeABarChart.purs" (line 33, column 3):
expecting indentation

That's from before your fix to psc. Now it looks like this:

[14:29:04] Error: "/Users/tom/code/purescript-d3-examples/src/LetsMakeABarChart.purs" (line 33, column 3):
expecting indentation

Much nicer.

@ethul
Copy link
Contributor

ethul commented Jul 5, 2014

That's a good point. I think it makes sense to collect stderr and stdout into buffers. I've opened issue #7 to track this.

Thanks!

@pelotom pelotom deleted the avoid-empty-error-messages branch July 5, 2014 23:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants