I can find no reference in the Node documentation to "ENOENT" other than in 
regards to DNS functions, no description at all in the File System 
documentation on what the error objects are (other than examples using them 
as booleans or opaque types to be displayed or thrown), nothing even saying 
an "Error" type has a "code" member you can reliably do anything with.  I 
would not call that "well-documented".  Coming from Windows-land, having 
never seen "ENOENT" before, I just assumed that was an internal libuv 
identifier or something.

At least in any case I tested, if a file exists and is not readable, 
fs.exists returns "true", as I'd expect.  There are probably some cases 
(perhaps if the file is in a location you do not have access to, as opposed 
to the fairly common case of just being unable to access a file) where the 
current fs.exists would return "false", but that's just a really good 
argument that the current fs.exists should only return false if stat 
returned an error *and* that error was "ENOENT" or whichever set of error 
codes indicates non-existence, not that the API is flawed.  Abstracting 
away exactly which behaviors or error codes indicate "existence" is useful.

On Wednesday, August 22, 2012 2:32:43 PM UTC-7, Isaac Schlueter wrote:
>
> Yeah, Jimb, I'm not sure I know what you mean by "undocumented error 
> code values".  Node does assume some familiarity with Posix error code 
> values, but that's a very long and well-documented tradition. 
>
> Actually, your gist is a perfect example of why fs.exists is a) 
> unnecessary, and b) almost always the wrong idea.  In the first case, 
> if the file exists, but is not readable, then the fs.exists() will 
> return false, and your program will act as if the file is *missing*, 
> which is incorrect. 
>
>
> On Wed, Aug 22, 2012 at 2:10 PM, Nathan Rajlich 
> <[email protected]<javascript:>> 
> wrote: 
> > Checking "err.code" for "ENOENT" is the most cross-platform and 
> > backwards compatible way to check for the existence of the file. 
> > 
> > On Wed, Aug 22, 2012 at 1:29 PM, Jimb Esser 
> > <[email protected]<javascript:>> 
> wrote: 
> >> Yeah, there are a lot of cases where "does not exists" as an "error" 
> needs 
> >> to be treated differently.  I tried making a "read from this file, 
> return a 
> >> default value if it does not exist" function without using fs.exists, 
> and 
> >> was unable to do so efficiently without relying on undocumented error 
> code 
> >> values [1].  It's very unclear if that code will work on different 
> versions 
> >> of node let alone different operating systems.  It's vitally important 
> in 
> >> cases like "rename this file to a backup before overwriting" that an 
> "error" 
> >> in the process is treated differently than "file does not exists", so 
> >> fs.exists does serve a purpose, even if its signature could have been 
> >> designed in a more conformant manner. 
> >> 
> >> [1] https://gist.github.com/3429037 
> >> 
> >> -- 
> >> Job Board: http://jobs.nodejs.org/ 
> >> Posting guidelines: 
> >> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines 
> >> You received this message because you are subscribed to the Google 
> >> Groups "nodejs" group. 
> >> To post to this group, send email to [email protected]<javascript:> 
> >> To unsubscribe from this group, send email to 
> >> [email protected] <javascript:> 
> >> For more options, visit this group at 
> >> http://groups.google.com/group/nodejs?hl=en?hl=en 
> > 
> > -- 
> > Job Board: http://jobs.nodejs.org/ 
> > Posting guidelines: 
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines 
> > You received this message because you are subscribed to the Google 
> > Groups "nodejs" group. 
> > To post to this group, send email to [email protected]<javascript:> 
> > To unsubscribe from this group, send email to 
> > [email protected] <javascript:> 
> > For more options, visit this group at 
> > http://groups.google.com/group/nodejs?hl=en?hl=en 
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to