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

check close callback is function #609

Closed
wants to merge 2 commits into from
Closed

check close callback is function #609

wants to merge 2 commits into from

Conversation

yosuke-furukawa
Copy link
Member

close methods have a callback. But the functions do not check the callback is a function.

@Qard
Copy link
Member

Qard commented Jan 26, 2015

I'd rather it fail for trying to use a non-function as a function than to fail silently.

@cjihrig
Copy link
Contributor

cjihrig commented Jan 26, 2015

Another alternative would be to check for a function and throw if it is not one. Failing silently is a bad idea though.

@yosuke-furukawa
Copy link
Member Author

Actually I agree with failing silently is a bad idea. However, I found some callback checks in net.js and dgram.js. So I guess when the callback is not a function, I should not throw any errors.

@rvagg
Copy link
Member

rvagg commented Jan 27, 2015

after having a quick cruise through lib I have to agree with @yosuke-furukawa that his proposal is idiomatic of what we have now in the networking code. There's a bunch of checks throwing TypeError in fs and some other modules but net is more relaxed about it.

My vote would be for letting this one through and someone having a second pass applying more rigour, particularly on the ones that are explicitly checking arguments named cb!

Then we'd need to discuss whether this would constitute a breaking change..

@evanlucas
Copy link
Contributor

Looks good to me.


var assert = require('assert'),
common = require('../common'),
dgram = require('dgram');
Copy link
Member

Choose a reason for hiding this comment

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

Minor nit: can you use a var (or let or const) declaration per line here?

@bnoordhuis
Copy link
Member

Style nits but essentially LGTM.

@yosuke-furukawa
Copy link
Member Author

I fixed all comments, thank you Ben.

@cjihrig
Copy link
Contributor

cjihrig commented Jan 27, 2015

@rvagg once this lands, I'll take a second pass at this and other code to find some places to introduce TypeErrors :-)


var server = net.createServer(assert.fail);

server.on('error', function(error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably let this error bubble up as well

Copy link
Member Author

Choose a reason for hiding this comment

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

oops...

@yosuke-furukawa
Copy link
Member Author

I fixed all comments. please review again.

@@ -341,7 +341,7 @@ function afterSend(err) {


Socket.prototype.close = function(callback) {
if (callback)
if (util.isFunction(callback))
Copy link
Contributor

Choose a reason for hiding this comment

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

can you change this to typeof check?

@yosuke-furukawa
Copy link
Member Author

Fixed!!

bnoordhuis pushed a commit that referenced this pull request Feb 2, 2015
PR-URL: #609
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Evan Lucas <evanlucas@me.com>
bnoordhuis pushed a commit that referenced this pull request Feb 2, 2015
PR-URL: #609
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Evan Lucas <evanlucas@me.com>
@bnoordhuis
Copy link
Member

Thanks Yosuke, landed in 207e48c...8c0742f.

@Qard @cjihrig @rvagg I mentioned only Evan and myself as reviewers because I wasn't sure if you reviewed / LGTM'd it or not.

@bnoordhuis bnoordhuis closed this Feb 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants