{"record":{"id":"441ceb68260caa1d","repo":"passbolt/passbolt_api","slug":"could-not-save-the-user-try-again-later","errorCode":null,"errorMessage":"Could not save the user, try again later.","messagePattern":"Could not save the user, try again later\\.","errorType":"http","errorClass":"InternalErrorException","httpStatus":500,"severity":"critical","filePath":"src/Model/Table/UsersTable.php","lineNumber":604,"sourceCode":"        // which causes isUnique build rule not to work when looking for duplicate entries.\n        $data['deleted'] = false;\n\n        // Check validation rules\n        $user = $this->buildEntity($data);\n        if ($user->getErrors()) {\n            throw new ValidationException(__('Could not validate user data.'), $user, $this);\n        }\n\n        // Check business rules\n        $this->checkRules($user);\n        if ($user->getErrors()) {\n            throw new ValidationException(__('Could not validate user data.'), $user, $this);\n        }\n\n        // Check for internal error on save\n        $user = $this->save($user, ['checkRules' => false]);\n        if (!$user) {\n            throw new InternalErrorException('Could not save the user, try again later.');\n        }\n\n        // Generate an authentication token\n        /** @var \\App\\Model\\Table\\AuthenticationTokensTable $AuthenticationTokens */\n        $AuthenticationTokens = TableRegistry::getTableLocator()->get('AuthenticationTokens');\n        $token = $AuthenticationTokens->generate($user->id, AuthenticationToken::TYPE_REGISTER);\n\n        // Generate event data\n        $eventData = ['user' => $user, 'token' => $token];\n        if ($control && $control->getId()) {\n            $eventData['adminId'] = $control->getId();\n            /** @psalm-suppress InvalidArgument */\n            $this->dispatchEvent(static::AFTER_REGISTER_SUCCESS_EVENT_NAME, $eventData, $this);\n        } else {\n            /** @psalm-suppress InvalidArgument */\n            $this->dispatchEvent(self::AFTER_SELF_REGISTER_SUCCESS_EVENT_NAME, $eventData, $this);\n        }\n","sourceCodeStart":586,"sourceCodeEnd":622,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Model/Table/UsersTable.php#L586-L622","documentation":"Thrown by UsersTable::register() when save($user, ['checkRules' => false]) returns false despite the entity passing validation and rules — a database write failure. InternalErrorException results, so the caller gets a 500 and the user record was not created (though the DB may need state reconciliation if side effects already ran).","triggerScenarios":"Registration flow (POST /users.json or self-registration) when the INSERT into users fails: connection loss, duplicate key race between checkRules and save, lock timeout, read-only DB, or trigger rejecting the insert.","commonSituations":"Two concurrent registrations with the same email racing past the isUnique check into a DB unique constraint failure; DB failover during registration; disk-full server; customized installs with failing triggers on users insert.","solutions":["Retry the registration once the database is healthy; if it was a unique-key race, handle the duplicate-username case explicitly.","Check application and DB error logs for the underlying SQL exception.","Verify DB connectivity, write permissions, and disk space.","Add a unique index on users.username at DB level and catch duplicate-key errors to return a clean 400 instead of 500."],"exampleFix":"// caller before\ncatch (InternalErrorException $e) { /* generic 500 */ }\n// after\ncatch (InternalErrorException $e) {\n    // check DB health / duplicate-key race, then retry or return 400\n}","handlingStrategy":"retry","validationCode":"if (!$this->Users->exists(['username' => $data['username']]) && $this->Users->getConnection()->isConnected()) { /* safe to attempt save */ }","typeGuard":null,"tryCatchPattern":"try { $user = $this->Users->register($data); } catch (\\Cake\\Http\\Exception\\InternalErrorException $e) { // check DB health / duplicate-key race; retry or map to 409 }","preventionTips":["Enforce a DB unique index on users.username.","Serialize registrations for the same email.","Monitor DB health and disk space.","Catch duplicate-key SQL errors and translate to clean 4xx responses."],"tags":["database","users","registration","internal-error"],"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"}