On Tue, 27 Dec 2016 13:28:19 -0800, comdog wrote: > 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