Search code examples
phplaravelamazon-s3laravel-9laravel-storage

Class \"League\\Flysystem\\UnableToWriteFile\" not found


We have a laravel application that has a command to move some files from one s3 bucket (different account) to another s3 bucket. This command runs once at day, and certainly every time it runs we get a log of the error stating:

{
    "class": "Error",
    "message": "Class \"League\\Flysystem\\UnableToWriteFile\" not found",
    "code": 0,
    "file": "/var/www/our-application/vendor/league/flysystem-aws-s3-v3/AwsS3V3Adapter.php:162",
    "trace": [
        "/var/www/our-application/vendor/league/flysystem-aws-s3-v3/AwsS3V3Adapter.php:140",
        "/var/www/our-application/vendor/league/flysystem/src/Filesystem.php:57",
        "/var/www/our-application/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php:331",
        "/var/www/our-application/app/Console/Commands/FileRetriever.php:79",
        "/var/www/our-application/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36",
        "/var/www/our-application/vendor/laravel/framework/src/Illuminate/Container/Util.php:41",
        "/var/www/our-application/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93",
        "/var/www/our-application/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37",
        "/var/www/our-application/vendor/laravel/framework/src/Illuminate/Container/Container.php:653",
        "/var/www/our-application/vendor/laravel/framework/src/Illuminate/Console/Command.php:136",
        "/var/www/our-application/vendor/symfony/console/Command/Command.php:312",
        "/var/www/our-application/vendor/laravel/framework/src/Illuminate/Console/Command.php:121",
        "/var/www/our-application/vendor/symfony/console/Application.php:1022",
        "/var/www/our-application/vendor/symfony/console/Application.php:314",
        "/var/www/our-application/vendor/symfony/console/Application.php:168",
        "/var/www/our-application/vendor/laravel/framework/src/Illuminate/Console/Application.php:102",
        "/var/www/our-application/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:129",
        "/var/www/our-application/artisan:37"
    ]
}

I am planning to run composer dump-autoload at some point in the production servers.

Also, we are not able to reproduce this locally.

This is how the relevant libraries look like in our composer.json

enter image description here


Solution

  • I did have this issue (but other classes not existing), after a long debugging session, I was able to reproduce this error, and, in my case, it was due to the virtual machine running out of memory (RAM) when some jobs where triggered.

    So, do check if you have a memory issue by triggering the code and then (if you are using Linux) run htop so you can see live the memory consumption and disregard that being the issue or find out that is the issue.