{"record":{"id":"105c67a0b6760c5c","repo":"coollabsio/coolify","slug":"unable-to-write-the-csv-file","errorCode":null,"errorMessage":"Unable to write the CSV file.","messagePattern":"Unable to write the CSV file\\.","errorType":"console","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"app/Console/Commands/Cloud/ExportUsers.php","lineNumber":124,"sourceCode":"        } finally {\n            fclose($subscribedOutput);\n            fclose($unsubscribedOutput);\n        }\n\n        $this->info(\"Exported {$subscribedCount} subscribed verified users to {$subscribedPath}\");\n        $this->info(\"Exported {$unsubscribedCount} unsubscribed verified users to {$unsubscribedPath}\");\n\n        return self::SUCCESS;\n    }\n\n    /**\n     * @param  resource  $output\n     * @param  array<int, mixed>  $fields\n     */\n    private function writeCsvRow($output, array $fields): void\n    {\n        if (fputcsv($output, $fields, ',', '\"', '') === false) {\n            throw new RuntimeException('Unable to write the CSV file.');\n        }\n    }\n}\n","sourceCodeStart":106,"sourceCodeEnd":128,"githubUrl":"https://github.com/coollabsio/coolify/blob/70b9acc42467278373e00de77abb40684e25b395/app/Console/Commands/Cloud/ExportUsers.php#L106-L128","documentation":"RuntimeException thrown by the private writeCsvRow() helper inside the cloud:export-users Artisan command when PHP's fputcsv() returns false. fputcsv only fails when the underlying stream cannot be written to: the handle is invalid or closed, the file was opened in a non-writable mode, the disk backing the 'backups' storage disk is full, or permissions were revoked mid-run. The command opens both CSV targets with fopen($path, 'wb') on the backups disk before the loop, so a successful open followed by a failed write points at runtime I/O failure (usually disk space), not a bad path.","triggerScenarios":"Running php artisan cloud:export-users on Coolify Cloud while (a) the filesystem behind the backups disk runs out of space as User rows stream in via lazyById(500), (b) the backups disk points at a full or unreachable remote mount (NFS/S3-compatible) that fails after fopen succeeded, or (c) the handle is closed/invalidated mid-export. Every writeCsvRow() call (header row plus one row per verified user) checks fputcsv's return and throws on the first false.","commonSituations":"Disk-full on the volume configured for the backups disk in config/filesystems.php; stale NFS mounts or expired S3-compatible credentials on the mount; large user tables where an external log-rotation or cleanup process touches the target files mid-export; running the command as a user whose permissions were changed after fopen.","solutions":["Check free space and write permission on the directory behind Storage::disk('backups') (df -h and touch on the backups path); free space if full.","Verify the backups disk entry in config/filesystems.php points at a reachable, writable location and remount/fix the mount if stale, then re-run php artisan cloud:export-users.","Confirm the CLI user has write access to cloud-users-subscribed.csv / cloud-users-unsubscribed.csv in that directory.","If the disk is remote, fix its credentials/mount health before re-running; the command deletes and recreates the files each run so it is safe to retry."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"$dir = dirname(Storage::disk('backups')->path('cloud-users-subscribed.csv'));\nif (! is_writable($dir) || disk_free_space($dir) < 1024 * 1024) {\n    // abort before opening any stream: the volume is unwritable or nearly full\n}","typeGuard":null,"tryCatchPattern":"try {\n    $this->writeCsvRow($output, $fields);\n} catch (RuntimeException $e) {\n    $this->error(\"CSV write failed mid-export: {$e->getMessage()}\");\n\n    return self::FAILURE;\n}","preventionTips":["Monitor free space on the backups volume and alert before it fills","Run the export as the same user that owns the backups directory","Smoke-test exports with a bounded query (limit) before running the full table"],"tags":["csv","filesystem","disk-full","artisan-command","io"],"backgroundTag":"file-write-failed","analyzedSha":"70b9acc42467278373e00de77abb40684e25b395","analyzedAt":"2026-08-17T01:41:01.313Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}