Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Add .flag to EACCES errors from the fs module. #7796

Closed
dantman opened this issue Jun 17, 2014 · 8 comments
Closed

Add .flag to EACCES errors from the fs module. #7796

dantman opened this issue Jun 17, 2014 · 8 comments

Comments

@dantman
Copy link

dantman commented Jun 17, 2014

fs passes errors that are annotated with .code = 'EACCES' and .path when a file cannot be read or written, it would be useful if the error also had a .flag matching the .flag / flags that the file was attempted to be opened with.

@ghost
Copy link

ghost commented Jun 17, 2014

Do u want to have the file access flags(like r w ) in the error object??

@dantman
Copy link
Author

dantman commented Jun 17, 2014

Basically. Functions like fs.open{Sync}, fs.readFile{Sync}, fs.writeFile{Sync}, etc... open a file with flags (in the case of ones other than fs.open those flags have defaults). If the user does not have the permission to perform the action then an EACCES error is thrown, and this error is already annotated with the .path of the file that the permissions were denied for. So while you can tell from the error alone what file permissions were denied for, you cannot tell what permissions were denied (which can be a pretty big difference). Hence why I'd like to see the denied .flag (or even .flags) added to the error.

This would allow an error handler further up the stack to identify the difference between the "You do not have permission to read " and "You do not have permission to write ".

@ghost
Copy link

ghost commented Jun 17, 2014

I think this feature is not added to the core module because it affects the performance of the entire system since on each error all the permissions must be obtained. But we can have some middleware like thing for our own purpose like this: https://gist.github.com/arjunrp/6169b4d3d18b06007a10

@dantman
Copy link
Author

dantman commented Jun 17, 2014

Those aren't the flags I want. I want the flags passed to fs.open/etc... simple 'r', 'w', 'a', 'r+', etc... not something that requires a full stat.

@trevnorris trevnorris added the fs label Jun 25, 2014
@trevnorris
Copy link

I'll happily entertain a PR. :)

@yamadapc
Copy link

I'll happily work on this and would like to use the opportunity to understand the node.js core a little better. If someone could point out some details about the fs implementation I'd be stoked.
The fs.open calls for instance, simply forward themselves to binding.open... From what I gather, binding is the js/cpp glue, but I've yet to understand the relationship well.

Could someone point out where the code for the binding module - regardless if it's C or JS - is located in the repo? I know this is somewhat lazy of me to ask, but some pointers are always nice :)

@yamadapc
Copy link

Never-mind, I've found it.

@jasnell
Copy link
Member

jasnell commented Jun 22, 2015

@yamadapc ... any updates on this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants