Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Return value of fs.unlinkSync not documented #9313

Closed
binarykitchen opened this issue Mar 2, 2015 · 24 comments
Closed

Return value of fs.unlinkSync not documented #9313

binarykitchen opened this issue Mar 2, 2015 · 24 comments

Comments

@binarykitchen
Copy link

Somehow http://nodejs.org/api/fs.html#fs_fs_unlinksync_path does not tell what it's return value is. I'd like to know it. Would be good to add this on that page.

Thanks!

@cjihrig
Copy link

cjihrig commented Mar 2, 2015

I don't think it returns anything (undefined). I personally think it would be useful if the return value of every method was documented, even when it's undefined, I'm not sure if everyone else would like that. Also, are you volunteering to do the potential docs work?

@binarykitchen
Copy link
Author

Well IMO those developers who have been working on fs should document it. It's a bad idea if someone else, who never dealt with fs, like me, is documenting it.

All I want to know what happens when unlinkSync() fails to perform due to invalid permissions? Will it throw an exception or just return false?

@cjihrig
Copy link

cjihrig commented Mar 3, 2015

Well IMO those developers who have been working on fs should document it. It's a bad idea if someone else, who never dealt with fs, like me, is documenting it.

You're right. Unfortunately, the documentation is what it is, and help is welcome.

All I want to know what happens when unlinkSync() fails to perform due to invalid permissions? Will it throw an exception or just return false?

An exception is thrown. In most cases, if an error would be passed to an asynchronous callback, it translates into a thrown exception in synchronous code.

@cjihrig cjihrig closed this as completed Mar 3, 2015
@misterdjules
Copy link

@binarykitchen @cjihrig We could make the introduction to http://nodejs.org/api/fs.html clearer by mentioning that the return value of synchronous versions is undefined, and that the way this API communicates errors is via exceptions that must be caught to be handled.

What do you think?

@binarykitchen
Copy link
Author

@misterdjules Perfect. But make sure to highlight it.

@cjihrig How about adding a policy enforcing every developer to update the documentation whenever they modify the API?

@misterdjules
Copy link

Ok, reopening this issue and added the easy label so that someone can pick it up as a first contribution.

@cjihrig
Copy link

cjihrig commented Mar 3, 2015

@binarykitchen such a policy exists. It probably always existed. Sometimes things just slip through the cracks. I'm not trying to make any excuses for the docs though.

@cjihrig cjihrig reopened this Mar 3, 2015
@tyleranton
Copy link

I'd like to take this if it's still up for grabs. It'd be my first contribution.

@misterdjules
Copy link

@tyleranton That's great!

Please not however that I do not agree anymore with what I said in my previous comment :)

Basically, I think that instead of mentioning in the introduction that "all functions for which the returned value is not mentioned return undefined", I think we sould mention the return value in each function's documentation section.

The reason for that is that users can jump to specific functions in the documentation without reading the introduction (it's an API documentation, not a tutorial), and thus they would miss this information.

So my suggestion would be, depending on the time you have, to either just fix the documentation for fs.unlinkSync by adding that it returns undefined, or if you have more time to fix that for every synchronous function of the fs module that returns undefined.

Does that make sense? @joyent/node-coreteam What do you think?

If you need help with any of this, I can help you in #libuv on Freenode (my nickname is jgi), or here on GitHub.

Thank you!

@tyleranton
Copy link

@misterdjules I'd be more than glad to update each function's doc. I'm assuming the change needs to made in both the nodejs website AND the fs.markdown in nodejs?

As for verbiage, is "Returns undefined." sufficient?

Thanks!

@misterdjules
Copy link

@tyleranton Excellent, thank you! The change actually needs to be made only in nodejs. For each new release, the docs are generated from node's repository and deployed to the nodejs.org website.

To test your changes to the documentation, you can run make doc and open out/doc/api/index.html.

"Returns undefined." is good, but we will probably want to format "undefined" as code with undefined.

@tyleranton
Copy link

@misterdjules Great! I'm already on it. This change needs to be made for every single synchronous form that doesn't already explicitly state what it returns, correct?

@misterdjules
Copy link

@tyleranton Right, and in addition to that we would want to check in the code that these functions actually return undefined. That's not always obvious, especially if you're new to the code base, but I can help you with that too.

Another thing I forgot to mention is that we'll want to make these changes to the v0.10 branch first, and then when it's done we'll merge these changes to v0.12 and master. So make sure you checkout the v0.10 branch before making the changes.

I won't be online tonight, but I'll be online tomorrow and Sunday so I'll be able to help you with this over the week-end if you'd like.

Thanks again!

@tyleranton
Copy link

@misterdjules Great, thanks! I've made the changes and tested them in markdown preview and the generated site.

I'll start checking the changes against the code and let you know if I get stuck tomorrow.

Excited to make my first contribution!

@tyleranton
Copy link

@misterdjules In a few instances, the async and sync functions are grouped together with a single description, like so:

fs.utimes(path, atime, mtime, callback)

fs.utimesSync(path, atime, mtime)

Change file timestamps of the file referenced by the supplied path.

Should this be changed to:

fs.utimes(path, atime, mtime, callback)

Change file timestamps of the file referenced by the supplied path.

fs.utimesSync(path, atime, mtime)

Synchronous version of fs.utimes. Returns undefined.

@misterdjules
Copy link

@tyleranton Yes, I think it should be changed like you did.

@tyleranton
Copy link

@misterdjules Great, I've made the changes. I've compared it to the code, and it all seems correct to me, but it may be a safe bet to double check behind me.

I'm going to go ahead and double check all of my changes again and with your go ahead, I'll commit and make a PR.

Thanks!

@tyleranton
Copy link

@misterdjules Pushed the changes to my branch. I'm ready to make a pull request.

@misterdjules
Copy link

@tyleranton Your changes look good, but it seems that they include content from the v0.12 branch.

Is it possible that you had the v0.12 branch loaded in your editor, then checked out the v0.10 branch and saved the doc/api/fs.markdown file from v0.12 that was loaded in memory in your local v0.10 branch?

@tyleranton
Copy link

@misterdjules Ah, that's probably what happened. I've copied the one from v0.10 and made the changes again. Do I need to provide a different commit message?

@misterdjules
Copy link

@tyleranton The commit message looked good 👍

@tyleranton
Copy link

@misterdjules Great, pushed the changes. Ready to make a PR.

@misterdjules
Copy link

@tyleranton Great! Before creating the pull request, you will need to squash the two commits that are in your branch into one commit with git rebase -i HEAD~2. Then create the pull request against the v0.10 branch in joyent/node and I'll review it.

If you need help with any of this I'm currently in #libuv on Freenode as jgi.

misterdjules pushed a commit to misterdjules/node that referenced this issue Mar 10, 2015
Clarify that synchronous functions in fs with no return value return
undefined.

Specify that fs.openSync() returns an integer and fs.existsSync()
returns true or false.

Fixes nodejs#9313

PR: nodejs#9359
PR-URL: nodejs#9359
Reviewed-By: Julien Gilli <[email protected]>
@misterdjules
Copy link

Fixed by 51fe319, thank you @binarykitchen, @tyleranton and @cjihrig!

Fishrock123 pushed a commit to Fishrock123/node that referenced this issue Jun 1, 2015
Clarify that synchronous functions in fs with no return value return
undefined.

Specify that fs.openSync() returns an integer and fs.existsSync()
returns true or false.

Fixes: nodejs/node-v0.x-archive#9313

PR: nodejs/node-v0.x-archive#9359
Reviewed-By: Julien Gilli <[email protected]>

PORT-FROM: joyent/node @ 51fe319
PR-URL: nodejs#1770
Reviewed-By: Roman Reiss <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>

Conflicts:
	doc/api/fs.markdown
andrewdeandrade pushed a commit to andrewdeandrade/node that referenced this issue Jun 3, 2015
Clarify that synchronous functions in fs with no return value return
undefined.

Specify that fs.openSync() returns an integer and fs.existsSync()
returns true or false.

Fixes: nodejs/node-v0.x-archive#9313

PR: nodejs/node-v0.x-archive#9359
Reviewed-By: Julien Gilli <[email protected]>

PORT-FROM: joyent/node @ 51fe319faf4399fd027f8b32d1c425200b911e44
PR-URL: nodejs/node#1770
Reviewed-By: Roman Reiss <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>

Conflicts:
	doc/api/fs.markdown
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants