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

No more sys_errlist #8234

Merged
merged 8 commits into from
Aug 20, 2021
Merged

No more sys_errlist #8234

merged 8 commits into from
Aug 20, 2021

Conversation

faho
Copy link
Member

@faho faho commented Aug 19, 2021

Description

This removes safe_strerror and safe_perror (which uses the former internally), and replaces it with hardcoded error messages.

The impetus for this is that glibc actually removed sys_errlist and according to #7006 we can't use strerror_r either.

I looked up the used errno values I could find. It's possible these are incomplete, in which case we get more "Unknown error $errno" messages, but I don't think that should be a common thing, and on current glibc that's already all of the errors here (except for the exec errors that we already explained).

Fixes issue #4183.

Ideally I would like this to be included in 3.4.0, provided we can get enough testing.

TODOs:

  • [N/A] Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

This no longer works on new glibcs because they removed sys_errlist.

So just hardcode the relevant errno messages (and phrase them better).

Fixes fish-shell#4183.
This also calls safe_strerror, which isn't usable anymore on new
glibc.

It is also ridiculous since the errors are bad to begin with.

We only use it for setpgid and fork, and I doubt there's gonna be a
lot more added to it.
@faho faho added this to the fish 3.4.0 milestone Aug 19, 2021
@faho faho changed the title No more sys errlist No more sys_errlist Aug 19, 2021
break;
}
case ETXTBSY: {
FLOGF_SAFE(exec, "Failed to execute process '%s': File is currently open for writing.", actual_cmd);
Copy link
Member Author

Choose a reason for hiding this comment

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

I specifically made these messages not just the ones we get by default.

That's because "text file is busy" is among the worst error messages I have ever read, mostly because it has a 98% chance of appearing when the file is not a text file (in the sense any user cares about).

It's kinda like if an ice cream place told you "machine not fillable" when they're out of a certain flavor. Might be true in the technical sense, but so misleading that it might as well not be said, at all.

Copy link
Member Author

Choose a reason for hiding this comment

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

So I would welcome more wording suggestions.

Copy link
Member

@krobelus krobelus left a comment

Choose a reason for hiding this comment

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

Looks great! The messages read nice.

src/postfork.cpp Outdated Show resolved Hide resolved
src/postfork.cpp Show resolved Hide resolved
src/postfork.cpp Outdated Show resolved Hide resolved
@@ -415,10 +456,31 @@ void safe_report_exec_error(int err, const char *actual_cmd, const char *const *
FLOGF_SAFE(exec, "Out of memory");
break;
}

case EACCES: {
FLOGF_SAFE(exec, "Failed to execute process '%s': The file could not be accessed.", actual_cmd);
Copy link
Member

Choose a reason for hiding this comment

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

probably run clang-format even if it makes this look slightly worse

src/postfork.cpp Outdated Show resolved Hide resolved
Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>
src/postfork.cpp Show resolved Hide resolved
@zanchey
Copy link
Member

zanchey commented Aug 20, 2021

We can use strerrordesc_np as a replacement for sys_errlist on platforms that support it (noted by @ridiculousfish), though that doesn't fix the issues of the poorly-written error descriptions.

@faho
Copy link
Member Author

faho commented Aug 20, 2021

We can use strerrordesc_np as a replacement for sys_errlist on platforms that support it

I don't know if strerrordesc_np provides any better guarantees than strerror_r ,which should be more widespread as it's in POSIX. We rejected that one in #7006.

Now unused too
Uh, yeah, EISDIR means it *is* a directory
@faho
Copy link
Member Author

faho commented Aug 20, 2021

Okay, tested on arch, alpine, FreeBSD, NetBSD, and Ubuntu and macOS on Github Actions.

It seems to compile everywhere and I can't find somewhere the errors are actually wrong, so I'm merging this now because it improves the status quo and I'd like to have it in 3.4.0.

More improvement is of course welcome!

@faho faho merged commit d4f7e25 into fish-shell:master Aug 20, 2021
@mqudsi
Copy link
Contributor

mqudsi commented Aug 20, 2021

I mean, you can’t beat error messages custom tailored to the faulting call - great work @faho.

@faho faho deleted the no-more-sys-errlist branch August 20, 2021 16:44
@zanchey
Copy link
Member

zanchey commented Aug 22, 2021

strerrordesc_np is specifically marked as async-signal-safe, but yeah, this is good

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants