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

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

Closed
jnj16180340 opened this issue Oct 26, 2016 · 1 comment · Fixed by #96
Closed

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

jnj16180340 opened this issue Oct 26, 2016 · 1 comment · Fixed by #96

Comments

@jnj16180340
Copy link
Contributor

jnj16180340 commented Oct 26, 2016

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 nodejs/node#2768 etc.), I'm using it for compatibility between node 4 and 6

@pabigot
Copy link
Contributor

pabigot commented Oct 26, 2016

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.

@raszi raszi closed this as completed in #96 Nov 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants