develooper Front page | perl.perl5.porters | Postings from June 2017

Re: open '>:encoding(UTF-8)' masking write errors?

Thread Previous
From:
Sawyer X
Date:
June 20, 2017 18:09
Subject:
Re: open '>:encoding(UTF-8)' masking write errors?
Message ID:
fac7f066-0a8f-9074-6c87-09078b0acb1c@gmail.com


On 06/17/2017 10:25 AM, Dave Mitchell wrote:
> Consider the following code:
>
>     my $data = 'x' x 1024;
>     my $file = '/dev/full';
>
>     open my $out, '>:encoding(UTF-8)', $file
>         or die "Error: can't open '$file' for writing: $!\n";
>     print $out $data or die "Error: writing to file '$file': $!\n";
>     close $out       or die "Error: closing file '$file': $!\n";
>
> It runs without error, which I find surprising and disturbing.
> Changing the open line to
>
>     open my $out, '>', $file
>
> gives the error I expect:
>
>     Error: closing file '/dev/full': No space left on device
>
> Is this a bug or do I have unrealistic expectations?

I would consider it wrong. Is the OS error swallowed by the encoding IO
layer?

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About