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

[discussion] ErrorKind::InvalidFilename from io_error_more #130192

Open
GrigorenkoPV opened this issue Sep 10, 2024 · 1 comment
Open

[discussion] ErrorKind::InvalidFilename from io_error_more #130192

GrigorenkoPV opened this issue Sep 10, 2024 · 1 comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@GrigorenkoPV
Copy link
Contributor

@rustbot label C-discussion

Main tracking issue: #86442

Background

The io_error_more feature introduced 21 new variants into ErrorKind. They were FCP'd back in December 2022, but there appeared to be quite a lot of disagreement about 4 of the added variants, so the stabilization (#106375) got stalled for over twenty months. Thankfully, the 17 uncontroversial variants got stabilized in #128316, so now we just need to iron out a satisfactory design for the remaining 4 variants, and then they can be stabilized too.

In order to not block any of the remaining variants on each other and to not intertwine the discussions, I've created 4 separate issues, which summarize the concerns & suggestions voiced up until this point and can serve as a place for further discussion.

InvalidFilename

Currently corresponds to ENAMETOOLONG on Unix, ERROR_FILENAME_EXCED_RANGE & ERROR_INVALID_NAME on Windows. (#86442 (comment))

Current docs description:

A filename was invalid.

This error can also cause if it exceeded the filename length limit.

Docs

I'm not sure "This error can also cause if it exceeded the filename length limit." is well-formed coherent English, but I'm not a native speaker.

Name capitalization

std uses file_name in functions, rather than filename. It'd be odd to break correspondence between snake_case and CamelCase, so I think this should be FileNameTooLong to match. Same goes for InvalidFileName.

Originally posted by Kornel in #79965 (comment)

Separate "the name is too long" case

I might be a little too late, but I'm not sure combining ERROR_FILENAME_EXCED_RANGE and ERROR_INVALID_NAME into InvalidFilename is a good idea. What was the reason behind this decision?

For example if one is writing an unarchiver to extract files, if a filename is too long one could simply truncate the filename and tell the user this. But if the filename is invalid/reserved (eg. COM) then the name would have to be completely different.

An app could guess which of the two it is, but it would be more straightforward if the two are distinguished from the start.

Originally posted by cktkw in #86442 (comment)

There is a long reply from Aritz Beobide-Cardinal in #106375 (comment) arguing against the separation.

Map more raw os errors to this ErrorKind

I was speculating there might be an OS that returns "Invalid Filename" when the filename is too long.
In which case, this decision will make sense.
But otherwise, "Filename Too Long" is one of the few errors that seem to be consistent among platforms.

With current PR, Unix doesn't have InvalidFilename mapped to anything else (at least from my quick skim through sys/unix/mod.rs).
However, UNIX-like OS fails with varying error when invalid UTF-8 filename is used to open() in C.
Mac APFS fails with EILSEQ (Illegal byte sequence).
Linux EXT4 (formatted with strict case-insensitive option -O casefold -E encoding_flags=strict, because otherwise any byte sequence is allowed) fails with EINVAL(invalid argument).

In theory, I think these should be mapped to InvalidFilename in the context of File::open(), File::create(), etc. But I understand that that would need major rewrite.
I don't know enough to say what would be the best way, but current use of InvalidFilename doesn't feel optimal.

Originally posted by cktkw in #86442 (comment)

@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. C-discussion Category: Discussion or questions that doesn't represent real issues. labels Sep 10, 2024
@tsuyoshi2
Copy link

"This error can also cause if..." is, indeed, improper English. "Cause" is a transitive verb. It can be rephrased in the passive voice as "This error can be caused if...".

@dtolnay dtolnay added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants