Closed ebaudrez closed 3 years ago
It expects there to always be a data structure returned. If you want to end the subprocess in a failure state, you could throw an exception as that is handled.
Nothing here looks like a bug to me, it's tested behaviour. If you want to propose a better way to deal with it you're welcome to do so of course.
I'm trying to run code that calls
exit()
within aMojo::IOLoop::Subprocess
. This code illustrates my problem:This code fails while testing the exception
$err
. Instead of the expected empty value, an exception is raised:The exception carries a reference to the JSON handling code in
Mojo::JSON
, but the actual issue is inMojo::IOLoop::Subprocess::_start
. The relevant lines are 52 and 53:https://github.com/mojolicious/mojo/blob/f5e1c294d8b7c977a0f287b5e33a90257703a7b9/lib/Mojo/IOLoop/Subprocess.pm#L52 and https://github.com/mojolicious/mojo/blob/f5e1c294d8b7c977a0f287b5e33a90257703a7b9/lib/Mojo/IOLoop/Subprocess.pm#L53
At line 53, the output for the parent is serialized. However, this code doesn't have a chance to run if the child process calls
exit()
, as the exit is not caught by theeval
on line 52.Now I'm not sure whether you want to allow this usage, that's why I wrote "Potential bug" :) But if you want to allow
exit
ing in a subprocess, this ought to be fixed. Let me know if you need more information.Kind regards!