spatie / statamic-responsive-images

Responsive images for Statamic 3
MIT License
104 stars 29 forks source link

Unable to read file from location issue #171

Closed PhilippeGauthier closed 2 years ago

PhilippeGauthier commented 2 years ago

This is probably something on my end but I'm getting an error where if I turn SAVE_CACHED_IMAGES to false I get the following error:

Unable to read file from location: containers/assets/img/...file.jpg.

I ran php please responsive:regenerate previously and can confirm that the file that's throwing the error does exist. I'm wondering if the addon should be referencing img/containers/assets/img/...file.jpg instead? In assets.php I've got 'cache_path' => public_path('img'), so I'd think that would resolve that?

Thanks for your help!

final class UnableToReadFile extends RuntimeException implements FilesystemOperationFailed

{

    /**

     * @var string

     */

    private $location = '';

    /**

     * @var string

     */

    private $reason = '';

    public static function fromLocation(string $location, string $reason = '', Throwable $previous = null): UnableToReadFile

    {

        $e = new static(rtrim("Unable to read file from location: {$location}. {$reason}"), 0, $previous);

        $e->location = $location;

        $e->reason = $reason;

        return $e;

    }

    public function operation(): string

    {

        return FilesystemOperationFailed::OPERATION_READ;

    }

    public function reason(): string

    {

        return $this->reason;
ncla commented 2 years ago

Hi,

Please provide full error stack trace, you only provided the exception class.

What exactly is SAVE_CACHED_IMAGES? I see no mention of this in statamic/cms. Are you referring to assets.php config file setting image_manipulation.cache?

Is this in SSG environment? This might be a core issue. See: https://github.com/statamic/ssg/issues/110

Could you please provide a step by step reproduction for this bug? It is not clear how to reproduce this yet from the initial description. Would help speed up resolving this issue a lot.

PhilippeGauthier commented 2 years ago

Sorry - yes the SAVE_CACHED_IMAGES a setting that the Peak addon creates. It's an alias to the image_manipulation.cache setting. Setting it to false creates these errors while setting it to true seems to alleviate them.

It is not in SSG environment. Static caching is set to null.

Here's the full stack trace:

https://flareapp.io/share/V7j19EnP#F130

I ran the php please responsive:regenerate because this was an existing project with a ton of images. If I upload an image from the CP errors don't occur on that particular image. I've tried using generic tags like {{ responsive:hero_image }} and {{ responsive:hero_image glide:width="1600" }} and both throw errors.

Do you need any other info? Thanks for your response!

ncla commented 2 years ago

When you are stuck with this kind of error try running php please glide:clear, that should "solve" it I think. But I am still curious how you got here in first place to that error, as responsive:regenerate command will not execute if image_manipulation.cache is false.

ncla commented 2 years ago

Nevermind, I just tried this myself. Simply set image_manipulation.cache to true, ran php please responsive:generate, refreshed a page with responsive tag and got the same error. I think key thing is that when you toggle cache, it gets confused.

That will do for now, bug confirmed.

ncla commented 2 years ago

So looking into this a bit deeper, as long as you do not switch cache setting many times and just leave it one value - it should be fine.

I agree that this is not very pleasant and is a misleading experience though.

To get out of this error, after you have changed cache value, do php please glide:clear.

If it happens anyway without changing cache settings, for now you can disable placeholder generation by setting tag parameter placeholder="false".

ncla commented 2 years ago

Hey,

I found a workaround fix and published it in v2.14.2.

Let me know if you are still having trouble with this.

PhilippeGauthier commented 2 years ago

Works great. Thanks for the quick fix.