Dealing with Fallout
The much welcome and overdue sanification of the IO-subsystem lead to some fallout in some of my code that was enjoyably easy to fix.
Some IO-operations used to return False or undefined values on errors returned from the OS. Those have been fixed to return Failure. As a result some idioms don’t work as they used to.
my $v = §some-filename.txt".IO.open.?slurp // 'sane default';
The conditional method call operator
.? does not defuse Failure as a result the whole expression blows up when an error occures. Luckily
try can be used as a statement, which will return
Nil, so we can still use the defined-or-operator
// to assign default values.
my $v = (try "some-filename.txt".IO.open.slurpy) // 'sane default';
The rational to have IO-operations throw explosives is simple. Filesystem dealings can not be atomic (at least seen from the runtime) and can fail unexpectetly due to cable tripping. By packaging exceptions in Failure objects Perl 6 allows us to turn them back into undefined values as we please.