Skip Menu |

Subject: chdir appears to throw exception immediately
Date: Tue, 27 Dec 2016 13:27:18 -0800
To: rakudobug [...] perl.org
From: brian d foy <brian.d.foy [...] gmail.com>
Download (untitled) / with headers
text/plain 1.5k
Using chdir with a non-existent directory appear to throw the exception immediately rather than using fail. The docs say (https://docs.perl6.org/type/IO$COLON$COLONPath#routine_chdir): If the directory change is successful then the IO::Path representing the target directory is returned, otherwise it will fail with X::IO::Chdir. Here's what I was doing. I expected to get a Failure object back from chdir, which would be "handled" by being evaluated in Boolean context. It would return False and run the unless block: put 'Current working directory is ' ~ $*CWD; my $file = '/not-there.txt'; put "$file is there: " ~ $file.IO.e; unless my $r = chdir $file { my $e = $r.exception; put "UNLESS: chdir failed: " ~ $e.^name ~ "\n" ~ $e.message; exit; } CATCH { put "CATCH: chdir failed: " ~ .^name ~ "\n" ~ .message; exit; } say "Cwd is now " ~ $*CWD; Instead, CATCH handles the immediately thrown exception: Current working directory is /Users/brian/Dropbox/~~Writing/Perl Writing/LearningPerl6/learning_perl_6/scratch CATCH: chdir failed: X::IO::Chdir Failed to change the working directory to '/not-there.txt': does not exist Failed to change the working directory to '/not-there.txt': does not exist in block <unit> at /Users/brian/Dropbox/~~Writing/Perl Writing/LearningPerl6/learning_perl_6/scratch/files.p6 line 8 Actually thrown at: in any at gen/moar/m-Metamodel.nqp line 3096 in block <unit> at /Users/brian/Dropbox/~~Writing/Perl Writing/LearningPerl6/learning_perl_6/scratch/files.p6 line 8
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 673b
On Tue, 27 Dec 2016 13:28:19 -0800, comdog wrote: Show quoted text
> Using chdir with a non-existent directory appear to throw the > exception > immediately rather than using fail.
A bit of a discussion for why chdir throws: https://irclog.perlgeek.de/perl6-dev/2016-12-28#i_13810888 But on further inspection, I see most of IO routines intercept Failures and throw them; search for ".throw" in https://github.com/rakudo/rakudo/blob/nom/src/core/IO/Path.pm and and https://github.com/rakudo/rakudo/blob/nom/src/core/io_operators.pm Yet the docs say they fail() and not throw. So it makes me wonder if it's a design decision to abandoning the Failure mechanism on all of IO routines?
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 629b
Some comments from moritz: https://irclog.perlgeek.de/perl6-dev/2016-12-28#i_13813983 And a short comment from TimToady on the topic: https://irclog.perlgeek.de/perl6-dev/2016-12-28#i_13814034 I also notice our *subs* throw, while *methods* fail(). The subs call the methods, check for failures and throw if detected. Based on what I see in the code sub move() appears to throw on anything which is not X::IO::Copy|X::IO::Unlink, and for those two it fails... and IO::Path doesn't provide a .move method at all. So it all seems to be pretty messy and in need of consistency. We just need to decide what the behaviour should be.
Subject: Re: [perl #130418] chdir appears to throw exception immediately
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
To: perl6-bugs-followup [...] perl.org
Date: Thu, 29 Dec 2016 00:04:52 +0100
Download (untitled) / with headers
text/plain 773b
Welcome to the world of the newio branch Show quoted text
> On 28 Dec 2016, at 20:03, Zoffix Znet via RT <perl6-bugs-followup@perl.org> wrote: > > Some comments from moritz: https://irclog.perlgeek.de/perl6-dev/2016-12-28#i_13813983 > And a short comment from TimToady on the topic: https://irclog.perlgeek.de/perl6-dev/2016-12-28#i_13814034 > > I also notice our *subs* throw, while *methods* fail(). The subs call the methods, check for failures and throw if detected. Based on what I see in the code sub move() appears to throw on anything which is not X::IO::Copy|X::IO::Unlink, and for those two it fails... and IO::Path doesn't provide a .move method at all. > > So it all seems to be pretty messy and in need of consistency. We just need to decide what the behaviour should be.
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.7k
On Tue, 27 Dec 2016 13:28:19 -0800, comdog wrote: Show quoted text
> Using chdir with a non-existent directory appear to throw the > exception > immediately rather than using fail. The docs say > (https://docs.perl6.org/type/IO$COLON$COLONPath#routine_chdir): > > If the directory change is successful then the IO::Path representing > the target directory is returned, otherwise it will fail with > X::IO::Chdir. > > Here's what I was doing. I expected to get a Failure object back from > chdir, which would be "handled" by being evaluated in Boolean context. > It would return False and run the unless block: > > put 'Current working directory is ' ~ $*CWD; > > my $file = '/not-there.txt'; > put "$file is there: " ~ $file.IO.e; > > unless my $r = chdir $file { > my $e = $r.exception; > put "UNLESS: chdir failed: " ~ $e.^name ~ "\n" ~ $e.message; > exit; > } > CATCH { > put "CATCH: chdir failed: " ~ .^name ~ "\n" ~ .message; > exit; > } > > say "Cwd is now " ~ $*CWD; > > Instead, CATCH handles the immediately thrown exception: > > Current working directory is /Users/brian/Dropbox/~~Writing/Perl > Writing/LearningPerl6/learning_perl_6/scratch > CATCH: chdir failed: X::IO::Chdir > Failed to change the working directory to '/not-there.txt': does not > exist > Failed to change the working directory to '/not-there.txt': does not > exist > in block <unit> at /Users/brian/Dropbox/~~Writing/Perl > Writing/LearningPerl6/learning_perl_6/scratch/files.p6 line 8 > > Actually thrown at: > in any at gen/moar/m-Metamodel.nqp line 3096 > in block <unit> at /Users/brian/Dropbox/~~Writing/Perl > Writing/LearningPerl6/learning_perl_6/scratch/files.p6 line 8
Thanks for the report. This was fixed some time in 2017.04 release. - IO grant


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org