raszi / node-tmp

Temporary file and directory creator for node.js
MIT License
737 stars 93 forks source link

errno constants aren't properly defined in node 6 #95

Closed jnj16180340 closed 8 years ago

jnj16180340 commented 8 years ago

node-tmp uses the internal 'constants' module to define error codes, such as EBADF and ENOENT which should be caught during cleanup. In node 6, error codes have been removed from the 'constants' module.

So, in node 6:

> process.binding('constants').EBADF
undefined
> process.binding('constants').ENOENT
undefined
> process.binding('constants').os.errno.EBADF
9
> process.binding('constants').os.errno.ENOENT
2

in node 4:

> process.binding('constants').EBADF                                                                                                                                                                                                                                                            
9                                                                                                                                                                                                                                                                                       
> process.binding('constants').ENOENT                                                                                                                                                                                                                                                           
2   
> process.binding('constants').os
undefined
> process.binding('constants').os
undefined

It seems that _c.ENOENT should be replaced by _c.os.errno.ENOENT etc. in node 6.

And _c = require('constants') should be replaced by _c = process.binding('constants')... not really sure why the two aren't equal.

Alternately, constants can be generated from require('os').constants.errno and require('fs').constants in node 6.

Although using process.binding isn't recommended (see https://github.com/nodejs/node/pull/2768 etc.), I'm using it for compatibility between node 4 and 6

pabigot commented 8 years ago

This seems related to my comment here. Even for older node.js releases I believe identifying the error by name instead of numeric code is more robust.