wazero
                                
                                 wazero copied to clipboard
                                
                                    wazero copied to clipboard
                            
                            
                            
                        dirfs.OpenFile can return EEXIST even if that is not defined FS.OpenFile in the interface documentation
In the interface FS.OpenFile, you have defined a set of errors that OpenFile can return.
https://github.com/tetratelabs/wazero/blob/ba569623fcb7b32bb8fc64dadc842672befd6819/experimental/sys/fs.go#L34...L39
However, if you follow what DirFS can return, there are more possible errors
https://github.com/tetratelabs/wazero/blob/ba569623fcb7b32bb8fc64dadc842672befd6819/experimental/sys/error.go#L10...L30
For example, if one opens file with O_CREAT and O_EXCL, but the file exists already, POSIX OS will return EEXIST.
I am implementing a custom FS, and I am not sure what to follow; there is a mismatch between the docs say and what the DirFS actually does.
When I follow it to the "other side", I see this
https://github.com/tetratelabs/wazero/blob/ba569623fcb7b32bb8fc64dadc842672befd6819/imports/wasi_snapshot_preview1/fs.go#L1534...L1540
EEXIST is there.
I don't see any list of allowed errnos here
https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#path_open
or here
https://wasix.org/docs/api-reference/wasi/path_open
so... I guess it can return EEXIST?
indeed, there are case where we return EEXIST https://github.com/tetratelabs/wazero/blame/main/experimental/sys/fs.go when we do it is usually because there is a test that requires it; e.g. in wasi-testsuite or other test suites. I will double check the docs to make sure they are up to date.
As written in #2104 I figured out there are other errors that are not in the docs.
I wanted to make a PR with all the possible errnos, but then I realized, all I am doing is rewriting https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html (the ERRORS part) to godoc format.
At which point I realized I might be even breaking copyright, as POSIX docs are copyrighted.
Wouldn't it be better to just link to the posix errors and say "here, there is a list"? It's documented better than will be here... the list on POSIX docs is very exhaustive.
Or, just rewrite the docs from "The below are expected otherwise..." to "Some possible errors: ..."?
Hm, but only SOME of those actually matter here. Hm. I guess I get back to rewriting. (But in my own words.)
edit: hm, no, I will not rewrite this, I can just copy-paste that
A component of the path prefix names an existing file that is neither a directory nor a symbolic link to a directory; or O_CREAT and O_EXCL are not specified, the path argument contains at least one non-
character and ends with one or more trailing characters, and the last pathname component names an existing file that is neither a directory nor a symbolic link to a directory; or O_DIRECTORY was specified and the path argument resolves to a non-directory file.