Skip Menu |

This queue is for tickets about the IO-Async CPAN distribution.

Report information
The Basics
Id: 98929
Status: resolved
Priority: 0/
Queue: IO-Async

People
Owner: Nobody in particular
Requestors: frioux [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.64



Subject: IO::Async::Process' on_exception has confusing args
Date: Tue, 16 Sep 2014 08:45:22 -0500
To: bug-IO-Async [...] rt.cpan.org
From: fREW Schmidt <frioux [...] gmail.com>
I may be wrong here, but I was under the impression that error callbacks usually have $self, $human_readable args as their first two args. The `on_exception` $human_readable arg for IO::Async::Process is (often?) blank. Example: #!/usr/bin/env perl use strict; use warnings; use IO::Async::Loop; use IO::Async::Process; my $loop = IO::Async::Loop->new; $loop->add( IO::Async::Process->new( command => [ 'herp', 'derp' ], on_finish => sub {}, on_exception => sub { my $self = shift; use Devel::Dwarn; Dwarn \@_; }, ) ); $loop->run -- fREW Schmidt https://blog.afoolishmanifesto.com
Download (untitled)
application/pgp-signature 819b

Message body not shown because it is not plain text.

On Tue Sep 16 09:44:29 2014, frew wrote: Show quoted text
> I may be wrong here, but I was under the impression that error > callbacks usually have $self, $human_readable args as their first two > args. The `on_exception` $human_readable arg for IO::Async::Process > is (often?) blank. Example:
Future failure ones do, yes; but this one massively predates them: =head2 on_exception $exception, $errno, $exitcode Invoked when the process exits by an exception from C<code>, or by failing to C<exec(2)> the given command. C<$errno> will be a dualvar, containing both number and string values. In this scenario it's quite likely that $exception will be empty if the failure was an exec() failure. I'll see if I can work out some better documentation on this one. -- Paul Evans
Patched -- Paul Evans
Subject: rt98929.patch
=== modified file 'lib/IO/Async/Process.pm' --- lib/IO/Async/Process.pm 2014-07-11 14:16:53 +0000 +++ lib/IO/Async/Process.pm 2014-10-17 16:32:50 +0000 @@ -86,6 +86,26 @@ If this is not provided and the process exits with an exception, then C<on_finish> is invoked instead, being passed just the exit code. +Since this is just the results of the underlying C<< $loop->spawn_child >> +C<on_exit> handler in a different order it is possible that the C<$exception> +field will be an empty string. It will however always be defined. This can be +used to distinguish the two cases: + + on_exception => sub { + my ( $self, $exception, $errno, $exitcode ) = @_; + + if( length $exception ) { + print STDERR "The process died with the exception $exception " . + "(errno was $errno)\n"; + } + elsif( ( my $status = W_EXITSTATUS($exitcode) ) == 255 ) { + print STDERR "The process failed to exec() - $errno\n"; + } + else { + print STDERR "The process exited with exit status $status\n"; + } + } + =cut =head1 CONSTRUCTOR
Released -- Paul Evans