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

nqp::writefh needs to type exceptions #574

Open
ajs opened this issue Aug 16, 2019 · 1 comment
Open

nqp::writefh needs to type exceptions #574

ajs opened this issue Aug 16, 2019 · 1 comment

Comments

@ajs
Copy link

ajs commented Aug 16, 2019

There are two related issues here, and since this touches all three layers (Rakudo, NQP, vm (e.g. MoarVM)) I wasn't sure where to submit it, but I think NQP, being the glue is the right place to at least ask.

  • MoarVM does not type exceptions for errno, and we blindly pass those AdHocs up the chain
  • NQP/Rakudo do not handle EPIPE in a standard way

Using Rakudo from the command-line:

$ perl6 -e 'say 1; say 2' | head -1
1
Unhandled exception: Failed to write bytes to filehandle: Broken pipe

This exception is an AdHoc because it's generated in MoarVM:

MVM_exception_throw_adhoc(tc, "Failed to write bytes to filehandle: %s",
    strerror(save_errno));

Which means that code handling routine IO exceptions like this need to string-match the exception text, which is clearly LTA:

put $foo; CATCH { when /'Failed to write bytes to filehandle'/ {exit} }

I believe that the correct solution, here is multi-part:

  • in the backends, errno should map to typed exceptions (does this require the HLL to provide a set of pre-defined typed exceptions, e.g. X::IO::Pipe at startup, if so, then does NQP have a way to pass those down?)
  • in NQP or Rakudo (not sure which) the default response to a broken pipe exception should be to exit silently (Perl 5, Python and nearly every other high level language does this, and it's more or less required in order to interoperate cleanly with Unix-like OSes which treat reading all output from a program as strictly optional)
@ajs
Copy link
Author

ajs commented Aug 16, 2019

Funny side-note: I have a vague memory that I may have been the one to report this bug back in the pugs days, or was at least active in explaining the Unix pipeline philosophy when it came up. :-)

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

No branches or pull requests

1 participant