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

exception in child Perl sub causes execution to escape run (and isn't returned to parent) #122

Open
djerius opened this issue Apr 6, 2018 · 0 comments

Comments

@djerius
Copy link
Contributor

djerius commented Apr 6, 2018

When a Perl subroutine is run as the child, I expect that an exception thrown in the sub will get propagated up to the parent,

From the fine manual

start() pauses the parent until the child executes the command or CODE reference and propagates any exceptions thrown (including exec() failure) back to the parent. This has several pleasant effects: any exceptions thrown in the child, including exec() failure, come flying out of start() or run() as though they had occurred in the parent.

However, unless I'm totally misunderstanding things, this doesn't happen. Here's some sample code:

use IPC::Run 'run';

print STDERR "Parent $$\n";

sub child {
    print STDERR "Child $$\n";
    die("Child dies");
}

sub parent {
    run \&child;
}
eval { parent } ;

if ( $@ ) {
    print "$$ error: $@\n";
}
else {
    print "$$ no error\n";
}

Here's what I expect to happen.

  1. Parent runs child
  2. Child dies, returns immediately from die() to parent
  3. Exception is magically massaged so that run() in parent throws child's exception
  4. eval in parent catches child's exception.

Here's some output:

Parent 26043
Child 26086
26086 error: Child dies at ../../IPC-Run/child_dies2.pl line 9.

26043 no error

Notice that it is the child that catches the error and prints it, actually continuing (because run is not trapping the error) to execute after the end of the child subroutine when it should have returned to the parent. The parent does not see the exception at all.

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