-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
error.PermissionDenied
vs error.AccessDenied
#16782
Comments
mismatch seems inherited
|
I was wrong. There's at least one: Lines 5591 to 5610 in e078324
|
I’m writing Zig bindings to a C library for a Linux system administration application—this is the lens through which I’m viewing this issue. I want to keep C code and
The implication is that However, the distinction above turns out to be meaningful for the purpose of troubleshooting my (privileged) application. Thus, I’d like to be able to represent both constants in my error set type. How should I do that? Knowing that, at an upper layer of my application, I will be uniting my library-specific error set type with syscall-specific error set types in If there were only one representation for both Allow me to give a more concrete example where compressing the distinction away can be undesirable: the bpf(2) syscall. Since bpf(2) is a Linux-specific syscall, there’s no corresponding API in
Meanwhile,
I believe that the standard library should equip users with the constructs they need to handle situations such as these should they deem it meaningful for their use cases. If anything, my suggestion is to rename Nomenclature notwithstanding, I agree that an effort should be made to ensure a consistent mapping from |
Thanks for the excellent analysis, all! It seems to me that what this discussion boils down to is that I would argue that using the errno to decide error names would be more intuitive for anyone familiar with developing for *nix, would make porting code to zig easier, and minimize the future role of |
I spent a little time trying to clean this up (my fix for #22733 got out of hand). As noted above by @ok-ryoko, POSIX defines (As a use case for thinking about this, consider a directory with a regular file, another file you're not allowed to write (due to file permissions), and another file you're not allowed to write because its immutable -- opening the first file for writing should succeed, the second returns There is a bit of Zig Windows-only code that maps the Windows The harder problem I ran into is how this impacts Zig's std.fs.* APIs. It seems reasonable to me that Zig defines the std.fs.* APIs to return consistent error codes, independent of the host platform. Which to me implies Fundamentally, its not clear to me how tightly Zig error codes map to platform errno numbers. If its 1:1 then std.posix.* should return 1:1 mappings from errno to error (and Windows-only APIs should return Windows-ish errors?), right? But then higher level Zig APIs like std.fs.* and std.os.* probably need distinct errors for their cross-platform, slightly higher-level semantics? (That is, the std.fs API error sets should not just extend POSIX error sets.) Alternatively, Zig could declare that, in this case, the |
…ionDenied AccessDenied is returned if the file mode bit (user/group/other rwx bits) disallow access. PermissionDenied is returned if something else denies access (immutable bit, SELinux, capabilities, etc). This somewhat subtle distinction is a POSIX thing. This PR is effecitvely an update of PR ziglang#19193. See ziglang#16782 for the deeper problems with the AccessDenied/PermissionDenied duopoly. Tested locally with an immutable file. Fixes ziglang#22733 and ziglang#19162.
… PermissionDenied `EACCES` is returned if the file mode bit (i.e., user/group/other rwx bits) disallow access (mapped to `error.AccessDenied`). `EPERM` is returned if something else denies access (immutable bit, SELinux, capabilities, etc) and is mapped to `error.PermissionDenied`. This somewhat subtle no-access distinction is part of POSIX. This PR is effecitvely an update/simplification of PR ziglang#19193. See ziglang#16782 for the deeper problems with the AccessDenied/PermissionDenied duopoly. Tested locally with an immutable file. Fixes ziglang#22733 and ziglang#19162.
This PR consistently maps .ACCES into AccessDenied and .PERM into PermissionDenied. AccessDenied is returned if the file mode bit (user/group/other rwx bits) disallow access (errno was `EACCES`). PermissionDenied is returned if something else denies access (errno was `EPERM`) (immutable bit, SELinux, capabilities, etc). This somewhat subtle distinction is a POSIX thing. Most of the change is updating std.posix Error Sets to contain both errors, and then propagating the pair up through caller Error Sets. Fixes ziglang#16782
This PR consistently maps .ACCES into AccessDenied and .PERM into PermissionDenied. AccessDenied is returned if the file mode bit (user/group/other rwx bits) disallow access (errno was `EACCES`). PermissionDenied is returned if something else denies access (errno was `EPERM`) (immutable bit, SELinux, capabilities, etc). This somewhat subtle distinction is a POSIX thing. Most of the change is updating std.posix Error Sets to contain both errors, and then propagating the pair up through caller Error Sets. Fixes ziglang#16782
These two error names are common through the Zig codebase, but they seem to be used pretty much interchangeably and don't seem to ever be used to convey unique information, so it seems like one canonical version should be chosen and used everywhere (or a distinction should be made about when to use one over another).
Some evidence for why I think it might make sense to merge them:
There is no explicit error set that I can find that includes bothPermissionDenied
andAccessDenied
, meaning that there is (presumably) nothing that intentionally uses one name over another to convey unique information. Put another way, there wouldn't be any information that is currently conveyed that would be lost if they were merged.error.PermissionDenied
vserror.AccessDenied
#16782 (comment)error.AccessDenied => return error.PermissionDenied
(and more will be added by Windows: FixTooManyParentDirs
handling for paths that shouldn't be cwd-relative #16783).ACCESS_DENIED => return error.PermissionDenied
and 7 instances of.ACCES => return error.PermissionDenied
.PERM => return error.AccessDenied
In terms of which is more common:
return error.PermissionDenied
return error.AccessDenied
The text was updated successfully, but these errors were encountered: