Skip to content

Commit

Permalink
Improve error on spew to missing directory
Browse files Browse the repository at this point in the history
  • Loading branch information
xdg committed Apr 24, 2024
1 parent 7a84e3c commit 4581f2f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/Path/Tiny.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2140,7 +2140,14 @@ sub spew {
my $resolved_path = $self->_resolve_symlinks;
my $temp = $resolved_path->_replacment_path;

my $fh = $temp->filehandle( { exclusive => 1, locked => 1 }, ">", $binmode );
my $fh;
my $ok = eval { $fh = $temp->filehandle( { exclusive => 1, locked => 1 }, ">", $binmode ); 1 };
if (!$ok) {
my $msg = ref($@) eq 'Path::Tiny::Error'
? "error opening temp file '$@->{file}' for atomic write: $@->{err}"
: "error opening temp file for atomic write: $@";
$self->_throw('spew', $self->[PATH], $msg);
}
print( {$fh} map { ref eq 'ARRAY' ? @$_ : $_ } @data) or self->_throw('print', $temp->[PATH]);
close $fh or $self->_throw( 'close', $temp->[PATH] );

Expand Down

0 comments on commit 4581f2f

Please sign in to comment.