Skip to content

Commit

Permalink
check for null when calling Storage::readStream()
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmajor committed May 4, 2024
1 parent 4c28264 commit 2a9d081
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions app/Images/Exceptions/FailedToReadStream.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Images\Exceptions;

use Exception;

class FailedToReadStream extends Exception
{
public function __construct(
public string $path,
) {
parent::__construct("Failed to read stream for file at {$this->path}.");
}
}
4 changes: 3 additions & 1 deletion app/Images/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Images;

use App\Images\Exceptions\FailedToReadStream;
use App\Images\Exceptions\OriginalDoesNotExist;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
Expand Down Expand Up @@ -155,7 +156,8 @@ protected function deleteResponsiveVariants(): bool
*/
public function readStream()
{
return static::disk()->readStream($this->originalPath());
return static::disk()->readStream($path = $this->originalPath())
?? throw new FailedToReadStream($path);
}

public static function disk(): FilesystemAdapter
Expand Down

0 comments on commit 2a9d081

Please sign in to comment.