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

strerror based on ErrorKind is technically valid but surprising #3612

Open
saethlin opened this issue May 18, 2024 · 3 comments
Open

strerror based on ErrorKind is technically valid but surprising #3612

saethlin opened this issue May 18, 2024 · 3 comments
Labels
A-shims Area: This affects the external function shims C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement

Comments

@saethlin
Copy link
Member

POSIX says precious little about what strerror does other than it produces a string. https://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html

The current implementation we have for strerror is based on converting the error code to a std::io::ErrorKind:
https://github.com/rust-lang/miri/blob/e1099c653869d18d2590bc3366b74b96a70997b1/src/shims/unix/foreign_items.rs#L571C34-L576

This conversion is lossy. In particular, both ENOTSUP and ENOSYS map to ErrorKind::Unsupported, even though every libc will produce different error messages for those. It would be nice if we could mirror the behavior of a good libc. Error reporting is not the right place to follow only the letter of the law.

@RalfJung
Copy link
Member

The current implementation mostly exists so we don't have to maintain a table of strings (for error descriptions) ourselves, but can reuse someone else's code...

@RalfJung RalfJung added C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement A-shims Area: This affects the external function shims labels May 18, 2024
@RalfJung
Copy link
Member

In particular, both ENOTSUP and ENOSYS map to ErrorKind::Unsupported

I can't find ENOTSUP mapping to anything? Where is it mapped to ErrorKind::Unsupported?

@saethlin
Copy link
Member Author

Ah! Yes. The library simply does not have such a mapping at all, which means that our shim doesn't know how to construct strings for errors not exposed by the standard library.

Where is it mapped to ErrorKind::Unsupported?

I was misremembering an FCP discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-shims Area: This affects the external function shims C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement
Projects
None yet
Development

No branches or pull requests

2 participants