{"record":{"id":"409a4ecd719bf5d6","repo":"passbolt/passbolt_api","slug":"could-not-save-the-folder-history","errorCode":null,"errorMessage":"Could not save the folder history.","messagePattern":"Could not save the folder history\\.","errorType":"http","errorClass":"Cake\\Http\\Exception\\InternalErrorException","httpStatus":500,"severity":"critical","filePath":"plugins/PassboltCe/Folders/src/Model/Table/FoldersHistoryTable.php","lineNumber":173,"sourceCode":"     * @throws \\App\\Error\\Exception\\ValidationException\n     * @throws \\Cake\\Http\\Exception\\InternalErrorException\n     */\n    public function create(array $data): FolderHistory\n    {\n        // Folder.Id becomes FolderHistory.FolderId\n        $data['folder_id'] = $data['id'];\n        unset($data['id']);\n\n        // Check validation rules.\n        $folderHistory = $this->buildEntity($data);\n        if ($folderHistory->getErrors()) {\n            throw new ValidationException(__('Could not validate folder history data.', true), $folderHistory, $this);\n        }\n        $folderHistory = $this->save($folderHistory);\n\n        // Check for errors while saving.\n        if (!$folderHistory) {\n            throw new InternalErrorException('Could not save the folder history.');\n        }\n\n        // Check for validation errors. (associated models too).\n        if ($folderHistory->getErrors()) {\n            throw new ValidationException(__('Could not validate folder history data.'), $folderHistory, $this);\n        }\n\n        return $folderHistory;\n    }\n}\n","sourceCodeStart":155,"sourceCodeEnd":184,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Folders/src/Model/Table/FoldersHistoryTable.php#L155-L184","documentation":"After validation passes, FoldersHistoryTable::create() calls save(); when save() returns false (the entity could not be persisted), an InternalErrorException with 'Could not save the folder history.' is thrown. This indicates a persistence-level failure rather than a validation problem.","triggerScenarios":"save() on the FoldersHistory entity returns false — typically a database-level failure: duplicate primary key on folder_id/id mapping, constraint violations not caught by validation, database connection issues, or transaction/locking problems.","commonSituations":"Database down or migration missing (folders_history table absent/outdated schema), unique constraint collisions when the same folder id is written concurrently, or storage backend (MySQL/Postgres) rejecting the insert due to column length/encoding.","solutions":["Check the application/database error logs for the underlying SQL exception raised during save().","Verify the folders_history table schema is up to date (run migrations, e.g. `ddev refresh` or cake migrations migrate).","Confirm database connectivity and that the storage backend (MySQL/MariaDB/Postgres) is healthy.","Check for unique/constraint conflicts on folder_id and handle retries or deduplication in the calling code."],"exampleFix":"// before\n$folderHistory = $this->save($folderHistory); // silent false -> InternalError\n// after\n$folderHistory = $this->save($folderHistory);\nif (!$folderHistory) {\n    $this->log('Folder history save failed: ' . json_encode($folderHistory->getErrors()), 'error');\n    throw new InternalErrorException('Could not save the folder history.');\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    $foldersHistoryTable->create($data);\n} catch (InternalErrorException $e) {\n    // log DB errors, verify schema/migrations and connectivity, then retry or alert\n    Log::error('Folder history persistence failed: ' . $e->getMessage());\n}","preventionTips":["Run database migrations after every deployment so folders_history schema matches the model.","Monitor database connectivity and lock/timeout metrics in production.","Log the underlying PDO/SQL exception when save() returns false to expose the root cause.","Handle concurrent writes to the same folder id to avoid unique constraint conflicts."],"tags":["database","save-failure","folders-history"],"backgroundTag":"database-write-failed","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}