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: System Error description incorrectly equates errno and code properties #6649

Closed
pabigot opened this issue May 9, 2016 · 7 comments
Closed
Labels
doc Issues and PRs related to the documentations.

Comments

@pabigot
Copy link
Contributor

pabigot commented May 9, 2016

The documentation for System Errors specifies:

Returns a string representing the error code, which is always E followed by a sequence of capital letters, and may be referenced in man 2 intro.
The properties error.code and error.errno are aliases of one another and return the same value.

In 4.x and (by inspection) 6.x this is incorrect; the error.errno property is an integer error code, as set by this code for ErrnoException in src/node.cc:

Local<Object> obj = e->ToObject(env->isolate());
obj->Set(env->errno_string(), Integer::New(env->isolate(), errorno));
obj->Set(env->code_string(), estring);

Reproduce with anything like:

try {
  require('fs').openSync('/no/such/file', 'r');
} catch (e) {
  console.log(e);
}
@evanlucas
Copy link
Contributor

Hmmm I'm getting different results:

$ node -e 'try { require("fs").openSync("/no/such", "r") } catch (err) { console.log(process.version, err.code) }'
v4.4.4 ENOENT

$ node -e 'try { require("fs").openSync("/no/such", "r") } catch (err) { console.log(process.version, err.code) }'
v5.11.1 ENOENT

$ node -e 'try { require("fs").openSync("/no/such", "r") } catch (err) { console.log(process.version, err.code) }'
v6.1.0 ENOENT

@evanlucas
Copy link
Contributor

ah scratch that, you're checking errno, not code

@evanlucas
Copy link
Contributor

I would say that this is a documentation issue. Want to submit a PR?

@claudiorodriguez claudiorodriguez added the doc Issues and PRs related to the documentations. label May 9, 2016
@pabigot
Copy link
Contributor Author

pabigot commented May 9, 2016

@evanlucas I'm going to say "no". errno values are generally positive integers with a system-specific value for a given string representation. That the fs.openSync call sets the property to -2 indicates somebody's encoding additional information (possibly just indicating an error through a return value that would otherwise be a non-negative descriptor, as on my system 2 corresponds to ENOENT). I could guess that taking the absolute value of errno would provide something interpretable, but it'd just be a guess. This should be documented by somebody who knows how Node.js decides what to put in the property and can provide guidance on how module writers should use it.

@addaleax
Copy link
Member

addaleax commented May 9, 2016

@pabigot The value of errno on Unices is explained in http://docs.libuv.org/en/v1.x/errors.html, and Node.js uses that value for code. That’s undocumented on Node.js’s side, though.

I don’t think there is a reason not to use .code instead of the .errno property, and I think @evanlucas is right, this is an error in the documentation.

@pabigot
Copy link
Contributor Author

pabigot commented May 9, 2016

@addaleax Thanks; with that I can work up some reasonable text. I agree it's a documentation issue and that most users are better off using .code. I'll get a PR in sometime in the next couple days.

@Trott
Copy link
Member

Trott commented Jul 7, 2017

This issue has been inactive for sufficiently long that it seems like perhaps it should be closed. Feel free to re-open (or leave a comment requesting that it be re-opened) if you disagree. I'm just tidying up and not acting on a super-strong opinion or anything like that.

@Trott Trott closed this as completed Jul 7, 2017
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.
Projects
None yet
Development

No branches or pull requests

5 participants