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

ServeDir: convert io::ErrorKind::NotADirectory to not_found #331

Merged
merged 3 commits into from
Feb 21, 2023

Conversation

syphar
Copy link
Contributor

@syphar syphar commented Feb 11, 2023

Motivation

In docs.rs we were seeing server errors on requests like /-/static/index.js/979790 when index.js actually existed.

The error we are seeing was: "Not a directory (os error 20)".

Solution

If I'm not missing something this should be a "not found" error.

I'm not 100% certain if accessing raw_os_error is good enough here, but ErrorKind::NotADirectory is not on stable yet (see io_error_more). Since this is coming from libc I assume this is portable.

I'm happy to add any needed changes, to close this if you disagree with my solution.

@adumbidiot
Copy link

Shouldn't this be gated to unix oses?

@syphar
Copy link
Contributor Author

syphar commented Feb 12, 2023

Shouldn't this be gated to unix oses?

Yep, you're absolutely right, I missed that the code definition I was referring to came from sys in the stdlib, which is OS specific. ( I didn't do too much rust cross-platform code until now)

Copy link
Collaborator

@Nehliin Nehliin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks looks good to me, I wonder if it's worth adding a comment to the ServeDir service highlighting this platform specific difference

@syphar
Copy link
Contributor Author

syphar commented Feb 13, 2023

Thanks looks good to me, I wonder if it's worth adding a comment to the ServeDir service highlighting this platform specific difference

You mean in the documentation?

@Nehliin
Copy link
Collaborator

Nehliin commented Feb 13, 2023

Yes exactly

@syphar
Copy link
Contributor Author

syphar commented Feb 13, 2023

I added a short sentence where I believ it could fit

@adumbidiot
Copy link

Yep, you're absolutely right, I missed that the code definition I was referring to came from sys in the stdlib, which is OS specific. ( I didn't do too much rust cross-platform code until now)

Not sure what you mean by sys, but the raw os code is specific for each os; on windows error code 20 doesn't have the same meaning as ENOTDIR.

Also, you could probably clean up your implementation a bit with https://doc.rust-lang.org/std/macro.cfg.html, since that looks like what you are trying to emulate with attribute macros.

@Nehliin Nehliin merged commit 987f5c9 into tower-rs:master Feb 21, 2023
@syphar syphar deleted the serve-dir-not-a-directory branch February 21, 2023 12:28
syphar added a commit to syphar/docs.rs that referenced this pull request Feb 26, 2023
syphar added a commit to syphar/docs.rs that referenced this pull request Feb 26, 2023
syphar added a commit to syphar/docs.rs that referenced this pull request Feb 26, 2023
syphar added a commit to rust-lang/docs.rs that referenced this pull request Feb 26, 2023
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 this pull request may close these issues.

3 participants