{"record":{"id":"ccd2dd3f27b68cf8","repo":"passbolt/passbolt_api","slug":"could-not-save-the-action-log","errorCode":null,"errorMessage":"Could not save the action log.","messagePattern":"Could not save the action log\\.","errorType":"exception","errorClass":"InternalErrorException","httpStatus":500,"severity":"error","filePath":"plugins/PassboltCe/Log/src/Model/Table/ActionLogsTable.php","lineNumber":156,"sourceCode":"            'status' => $status,\n        ];\n        // Check validation rules.\n        $log = $this->buildEntity($data);\n        if ($log->getErrors()) {\n            throw new ValidationException(__('Could not validate action log data.'), $log, $this);\n        }\n\n        /** @var \\Passbolt\\Log\\Model\\Entity\\ActionLog|bool $logSaved */\n        $logSaved = $this->save($log);\n\n        // Check for validation errors. (associated models too).\n        if ($log->getErrors()) {\n            throw new ValidationException(__('Could not validate action log data.'), $log, $this);\n        }\n\n        // Check for errors while saving.\n        if (!$logSaved) {\n            throw new InternalErrorException('Could not save the action log.');\n        }\n\n        return $logSaved;\n    }\n\n    /**\n     * Return a action_log entity.\n     *\n     * @param array $data entity data\n     * @return \\Passbolt\\Log\\Model\\Entity\\ActionLog\n     */\n    public function buildEntity(array $data): ActionLog\n    {\n        return $this->newEntity($data, [\n            'accessibleFields' => [\n                'id' => true,\n                'user_id' => true,\n                'action_id' => true,","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Log/src/Model/Table/ActionLogsTable.php#L138-L174","documentation":"ActionLogsTable::create() throws this InternalErrorException when the action log entity passes validation but the subsequent save() call returns false (or null). It signals an unexpected persistence failure that is not a validation problem — e.g. a database connectivity issue, schema mismatch, or a save callback aborting the write.","triggerScenarios":"Calling ActionLogsTable::create() with data that validates but fails at the database layer: DB connection dropped mid-request, missing action_logs table/column after incomplete migration, duplicate-key or integrity constraint violation surfaced through events rather than validation, or a Model.beforeSave rule returning false.","commonSituations":"Production environments where migrations were not run after a passbolt upgrade; disk-full or DB-max-connections conditions; custom plugins attaching beforeSave/beforeMarshal callbacks that silently abort log persistence.","solutions":["Check the database connectivity and error logs (CakePHP error.log) for the underlying save failure.","Run pending migrations (passbolt migrate / bin/cake migrations migrate) so the action_logs schema matches the code.","Temporarily wrap the save with error inspection (e.g. check connection->lastError or logs) to find the failing constraint or callback.","Verify no custom plugin beforeSave rules abort saving action logs.","severity_check: confirm the table's connection is healthy and disk space is available."],"exampleFix":"// before\n$logSaved = $this->save($log);\nif (!$logSaved) {\n    throw new InternalErrorException('Could not save the action log.');\n}\n// after\n$logSaved = $this->save($log);\nif (!$logSaved) {\n    $this->log(\n        'Action log save failed: ' . json_encode($log->getErrors()),\n        'error'\n    );\n    throw new InternalErrorException('Could not save the action log.');\n}","handlingStrategy":"try-catch","validationCode":"if (!$entity instanceof \\Passbolt\\Log\\Model\\Entity\\ActionLog) { throw new \\InvalidArgumentException('Expected ActionLog entity'); }","typeGuard":"function isValidActionLogData(array $data): bool { return isset($data['status']) && is_int($data['status']); }","tryCatchPattern":"try { $logsService->create($data); } catch (InternalErrorException $e) { // check DB health, alert, do not fail the user request for logging issues\n    Log::error('Action log persistence failed: ' . $e->getMessage());\n}","preventionTips":["Run migrations on every deploy (passbolt migrate).","Monitor database health (connections, disk space) in production.","Never abort user-facing requests solely because audit log persistence failed — log and degrade gracefully.","Keep beforeSave listeners on ActionLogs side-effect free or error-setting."],"tags":["database","logging","persistence","cakephp"],"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"}