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

Why doesn't Perl 6's try handle a non-zero exit in shell()? #6172

Closed
p6rt opened this issue Apr 4, 2017 · 6 comments
Closed

Why doesn't Perl 6's try handle a non-zero exit in shell()? #6172

p6rt opened this issue Apr 4, 2017 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Apr 4, 2017

Migrated from rt.perl.org#131097 (status was 'rejected')

Searchable as RT131097$

@p6rt
Copy link
Author

p6rt commented Apr 4, 2017

From @briandfoy

I originally asked about this on Stackoverflow
(http://stackoverflow.com/q/43199427/2766176)

This `try` catches the exception​:

  try die X​::AdHoc;
  say "Got to the end";

The output shows that the program continues​:

  Got to the end

If I attempt it with `shell` and a command that doesn't exit with 0,
the `try` doesn't catch it​:

  try shell('/usr/bin/false');
  say "Got to the end";

The output doesn't look like an exception​:

  The spawned command '/usr/bin/false' exited unsuccessfully (exit code​: 1)
  in block <unit> at ... line ...

What's going on that this makes it through the `try`?

--- Perl variables ---
Perl​: Perl 6
Executable​: perl6
Flavor​: Rakudo 2017.01
VM​: MoarVM 2017.01
Distro​: macosx
Kernel​: darwin
PERL6LIB​:

--- Other Environment ---
LANG​: en_US.UTF-8
LANGUAGE​: en_US.UTF-8
LC_ALL​: en_US.UTF-8
LESSCHARSET​: utf-8
LOCALE_I_WANT​: en_US.UTF-8
LOCAL_PATH​: /usr/local/bin
SHELL​: /bin/bash
SHLVL​: 1
TERM​: vt100

--
brian d foy <brian.d.foy@​gmail.com>
http://www.pair.com/~comdog/

@p6rt
Copy link
Author

p6rt commented Apr 4, 2017

From @zoffixznet

On Tue, 04 Apr 2017 02​:52​:53 -0700, comdog wrote​:

I originally asked about this on Stackoverflow
(http://stackoverflow.com/q/43199427/2766176)

This `try` catches the exception​:

try die X​::AdHoc;
say "Got to the end";

The output shows that the program continues​:

Got to the end

If I attempt it with `shell` and a command that doesn't exit with 0,
the `try` doesn't catch it​:

try shell('/usr/bin/false');
say "Got to the end";

The output doesn't look like an exception​:

The spawned command '/usr/bin/false' exited unsuccessfully (exit code​:
1)
in block <unit> at ... line ...

What's going on that this makes it through the `try`?

--- Perl variables ---
Perl​: Perl 6
Executable​: perl6
Flavor​: Rakudo 2017.01
VM​: MoarVM 2017.01
Distro​: macosx
Kernel​: darwin
PERL6LIB​:

--- Other Environment ---
LANG​: en_US.UTF-8
LANGUAGE​: en_US.UTF-8
LC_ALL​: en_US.UTF-8
LESSCHARSET​: utf-8
LOCALE_I_WANT​: en_US.UTF-8
LOCAL_PATH​: /usr/local/bin
SHELL​: /bin/bash
SHLVL​: 1
TERM​: vt100

Thank you for the report. However, there's no bug here.

try catches exceptions. shell() doesn't throw, but returns a Proc object.
Proc objects with non-zero exist status throw when sunk.

So in your code, the try gives a Proc object a pass, it immediately gets sunk, and explodes (outside of try).

You can use `try sink shell '/usr/bin/false'` to get it to explode inside of try.

We also have a support channel where you can ask questions like this one​: https://webchat.freenode.net/?channels=#perl6

@p6rt
Copy link
Author

p6rt commented Apr 4, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt closed this as completed Apr 4, 2017
@p6rt
Copy link
Author

p6rt commented Apr 4, 2017

@zoffixznet - Status changed from 'open' to 'rejected'

@p6rt
Copy link
Author

p6rt commented Apr 4, 2017

From @lizmat

Thanks for reporting!

Turns out this isn’t actually a bug, but the way shell() works. As Jonathan explained at​:

  https://irclog.perlgeek.de/perl6-dev/2017-04-04#i_14372945

the shell() function returns a Proc object. This only throws the shelling out failed and the Proc object is sunk.

So ENOTABUG.

On 4 Apr 2017, at 11​:52, brian d foy (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by "brian d foy"
# Please include the string​: [perl #​131097]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=131097 >

I originally asked about this on Stackoverflow
(http://stackoverflow.com/q/43199427/2766176)

This `try` catches the exception​:

try die X​::AdHoc;
say "Got to the end";

The output shows that the program continues​:

Got to the end

If I attempt it with `shell` and a command that doesn't exit with 0,
the `try` doesn't catch it​:

try shell('/usr/bin/false');
say "Got to the end";

The output doesn't look like an exception​:

The spawned command '/usr/bin/false' exited unsuccessfully (exit code​: 1)
in block <unit> at ... line ...

What's going on that this makes it through the `try`?

--- Perl variables ---
Perl​: Perl 6
Executable​: perl6
Flavor​: Rakudo 2017.01
VM​: MoarVM 2017.01
Distro​: macosx
Kernel​: darwin
PERL6LIB​:

--- Other Environment ---
LANG​: en_US.UTF-8
LANGUAGE​: en_US.UTF-8
LC_ALL​: en_US.UTF-8
LESSCHARSET​: utf-8
LOCALE_I_WANT​: en_US.UTF-8
LOCAL_PATH​: /usr/local/bin
SHELL​: /bin/bash
SHLVL​: 1
TERM​: vt100

--
brian d foy <brian.d.foy@​gmail.com>
http://www.pair.com/~comdog/

@p6rt
Copy link
Author

p6rt commented Apr 4, 2017

From @AlexDaniel

FWIW, another place where this was discussed​: https://rt.perl.org/Public/Bug/Display.html?id=130715
On 2017-04-04 04​:07​:03, elizabeth wrote​:

Thanks for reporting!

Turns out this isn’t actually a bug, but the way shell() works. As
Jonathan explained at​:

https://irclog.perlgeek.de/perl6-dev/2017-04-04#i_14372945

the shell() function returns a Proc object. This only throws the
shelling out failed and the Proc object is sunk.

So ENOTABUG.

On 4 Apr 2017, at 11​:52, brian d foy (via RT) <perl6-bugs-
followup@​perl.org> wrote​:

# New Ticket Created by "brian d foy"
# Please include the string​: [perl #​131097]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=131097 >

I originally asked about this on Stackoverflow
(http://stackoverflow.com/q/43199427/2766176)

This `try` catches the exception​:

try die X​::AdHoc;
say "Got to the end";

The output shows that the program continues​:

Got to the end

If I attempt it with `shell` and a command that doesn't exit with 0,
the `try` doesn't catch it​:

try shell('/usr/bin/false');
say "Got to the end";

The output doesn't look like an exception​:

The spawned command '/usr/bin/false' exited unsuccessfully (exit
code​: 1)
in block <unit> at ... line ...

What's going on that this makes it through the `try`?

--- Perl variables ---
Perl​: Perl 6
Executable​: perl6
Flavor​: Rakudo 2017.01
VM​: MoarVM 2017.01
Distro​: macosx
Kernel​: darwin
PERL6LIB​:

--- Other Environment ---
LANG​: en_US.UTF-8
LANGUAGE​: en_US.UTF-8
LC_ALL​: en_US.UTF-8
LESSCHARSET​: utf-8
LOCALE_I_WANT​: en_US.UTF-8
LOCAL_PATH​: /usr/local/bin
SHELL​: /bin/bash
SHLVL​: 1
TERM​: vt100

--
brian d foy <brian.d.foy@​gmail.com>
http://www.pair.com/~comdog/

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