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 <nat...@tootallnate.net> 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 <wastel...@gmail.com> 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 nodejs@googlegroups.com
>> To unsubscribe from this group, send email to
>> nodejs+unsubscr...@googlegroups.com
>> 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 nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscr...@googlegroups.com
> 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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to