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

doc: add callback function signatures in fs.md #13424

Closed

Conversation

matejkrajcovic
Copy link
Contributor

This is related to #11135.

Adds descriptions of callback parameters to function signatures as in child_process docs.

Checklist
Affected core subsystem(s)

doc, fs

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. labels Jun 3, 2017
@mscdex
Copy link
Contributor

mscdex commented Jun 3, 2017

I'm all for clearly documenting this but I'm not sure this is the best way to communicate the signature and/or possible values. For example, the error parameter may contain a false-y value and not an actual Error instance (so seeing the Error type for this parameter may throw new users off), or the error parameter may contain an Error instance and the other parameters either may not exist at all or they may be set to undefined. In the latter scenario this may not matter much in practice, it just depends on how exact we want to be in our documentation (e.g. in case someone is checking arguments.length in their callbacks).

@jasnell
Copy link
Member

jasnell commented Jun 4, 2017

I have to agree with @mscdex. I love that you're taking the time to document these... it is definitely needed. But we should find a way of representing them that is easier to follow. Perhaps:

  • callback {Function} callback(error, arg1, arg2)

Or something similar

Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

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

👍

@refack
Copy link
Contributor

refack commented Jun 4, 2017

I'm all for clearly documenting this but I'm not sure this is the best way to communicate the signature and/or possible values. For example, the error parameter may contain a false-y value and not an actual Error instance (so seeing the Error type for this parameter may throw new users off), or the error parameter may contain an Error instance and the other parameters either may not exist at all or they may be set to undefined. In the latter scenario this may not matter much in practice, it just depends on how exact we want to be in our documentation (e.g. in case someone is checking arguments.length in their callbacks).

IMHO not perfect but better than nothing.

@matejkrajcovic
Copy link
Contributor Author

matejkrajcovic commented Jun 13, 2017

  • Can really error argument be just falsy and not an instance of Error? I have checked multiple functions and tried to understand C++ code in src/node_file.cc and it seems to me it is always an instance of Error.
  • I've used this style of signatures to be consistent with child_process.fs and dns.fs. I can change it to callback {Function} callback(error, arg1, arg2) but then we also should change those files.

I prefer to leave callback arguments on separate lines. This seems clearer to me:

  • callback {Function}
    • err {Error}
    • written {integer}
    • string {string}

than this:

  • callback {Function} callback(err {Error}, written {integer}, string {string})

@mscdex
Copy link
Contributor

mscdex commented Jun 13, 2017

Can really error argument be just falsy and not an instance of Error?

Yes, when no error occurred.

@matejkrajcovic
Copy link
Contributor Author

matejkrajcovic commented Jun 13, 2017

I see. err is null when no error happens and arguments with results are undefined in case of error. Is this better?

  • callback {Function}
    • err {Error|null}
    • written {integer|undefined}
    • string {string|undefined}

@tniessen
Copy link
Member

tniessen commented Jul 3, 2017

I am sorry for the lack of feedback from our side.

  • callback {Function}
    • err {Error|null}
    • written {integer|undefined}
    • string {string|undefined}

IMO it is not better, I think it is more confusing than without those additions. I am fine with Error|null, but someone might complain that it is inconsistent. Alternatively, we could add a note after err within the same line, we do that for other parameters as well, but it would be quite repetitive as we have a lot of callbacks with an error parameter.

What do you think @mscdex ?

@mscdex
Copy link
Contributor

mscdex commented Jul 3, 2017

I agree that the currently proposed layout isn't ideal either. Also, the err argument may not always be null, it could be undefined as well for some parts of the API.

@BridgeAR
Copy link
Member

I think the proposal itself is better then the current situation and therefore I am +1 for this.

I think it makes sense to make clear that the error can be null (or undefined in some APIs, but I guess that is rare?) but I also agree that adding |undefined all the time might be confusing. Maybe a mixture would be a good compromise? It is not ideal but I think it makes it somewhat clearer.

  • callback {Function}
    • err {Error|null}
    • written {integer}
    • string {string}

Or we mark the other arguments as "optional" because they will only be returned in case err === null.

  • callback {Function}
    • err {Error|null}
    • [written {integer}]
    • [string {string}]

@BridgeAR
Copy link
Member

BridgeAR commented Sep 8, 2017

@matejkrajcovic this needs a rebase.

@matejkrajcovic
Copy link
Contributor Author

@BridgeAR rebased.

@BridgeAR
Copy link
Member

@mscdex are you fine with landing this as is? I think it is better than our current situation and we can still try to figure out how to improve this further at another point?

doc/api/fs.md Outdated
@@ -2471,6 +2518,8 @@ changes:
* `persistent` {boolean} **Default:** `true`
* `interval` {integer} **Default:** `5007`
* `listener` {Function}
* `current` {fs.Stat}
Copy link
Contributor

Choose a reason for hiding this comment

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

Both of these should be plural.

@BridgeAR
Copy link
Member

@matejkrajcovic seems like we are almost there and only one comment has to be addressed.

@matejkrajcovic
Copy link
Contributor Author

@BridgeAR it's fixed.

@BridgeAR
Copy link
Member

@BridgeAR
Copy link
Member

Landed in a636b72

@BridgeAR BridgeAR closed this Sep 28, 2017
BridgeAR pushed a commit that referenced this pull request Sep 28, 2017
PR-URL: #13424
Refs: #11135
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@matejkrajcovic matejkrajcovic deleted the doc-fs-callback-signatures branch September 28, 2017 05:37
MylesBorins pushed a commit to MylesBorins/node that referenced this pull request Sep 28, 2017
PR-URL: nodejs#13424
Refs: nodejs#11135
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this pull request Sep 29, 2017
PR-URL: #13424
Refs: #11135
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
addaleax pushed a commit to addaleax/ayo that referenced this pull request Sep 30, 2017
PR-URL: nodejs/node#13424
Refs: nodejs/node#11135
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this pull request Oct 3, 2017
PR-URL: #13424
Refs: #11135
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins MylesBorins mentioned this pull request Oct 3, 2017
MylesBorins pushed a commit that referenced this pull request Oct 3, 2017
PR-URL: #13424
Refs: #11135
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins
Copy link
Contributor

This does not land cleanly in LTS. Please feel free to manually backport by following the guide. Please also feel free to replace do-not-land if it is being backported

matejkrajcovic added a commit to matejkrajcovic/node that referenced this pull request Oct 18, 2017
PR-URL: nodejs#13424
Refs: nodejs#11135
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this pull request Oct 19, 2017
Backport-PR-URL: #16306
PR-URL: #13424
Refs: #11135
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins MylesBorins mentioned this pull request Oct 19, 2017
MylesBorins pushed a commit that referenced this pull request Oct 25, 2017
Backport-PR-URL: #16306
PR-URL: #13424
Refs: #11135
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this pull request Oct 26, 2017
Backport-PR-URL: #16306
PR-URL: #13424
Refs: #11135
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins MylesBorins mentioned this pull request Nov 3, 2017
vsemozhetbyt added a commit that referenced this pull request Jan 23, 2018
PR-URL: #18310
Fixes: #18305
Refs: #13424
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
evanlucas pushed a commit that referenced this pull request Jan 30, 2018
PR-URL: #18310
Fixes: #18305
Refs: #13424
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
MylesBorins pushed a commit that referenced this pull request Feb 27, 2018
PR-URL: #18310
Fixes: #18305
Refs: #13424
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
PR-URL: nodejs#18310
Fixes: nodejs#18305
Refs: nodejs#13424
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants