{"record":{"id":"318335b408131ff6","repo":"passbolt/passbolt_api","slug":"could-not-validate-action-data","errorCode":null,"errorMessage":"Could not validate action data.","messagePattern":"Could not validate action data\\.","errorType":"validation","errorClass":"ValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/Log/src/Model/Table/ActionsTable.php","lineNumber":127,"sourceCode":"     * Create a new action.\n     *\n     * @param string $id action id\n     * @param string $name name of the action\n     * @return \\Passbolt\\Log\\Model\\Entity\\Action\n     * @throws \\App\\Error\\Exception\\ValidationException\n     * @throws \\Cake\\Http\\Exception\\InternalErrorException\n     */\n    public function create(string $id, string $name): Action\n    {\n        $data = [\n            'id' => $id,\n            'name' => $name,\n        ];\n\n        // Check validation rules.\n        $action = $this->buildEntity($data);\n        if ($action->getErrors()) {\n            throw new ValidationException(__('Could not validate action data.', true), $action, $this);\n        }\n\n        /** @var \\Passbolt\\Log\\Model\\Entity\\Action $actionSaved */\n        $actionSaved = $this->save($action);\n\n        // Check for validation errors.\n        if ($action->getErrors()) {\n            throw new ValidationException(__('Could not validate action data.'), $action, $this);\n        }\n\n        // Check for errors while saving.\n        if (!$actionSaved) {\n            throw new InternalErrorException('Could not save the action.');\n        }\n\n        return $actionSaved;\n    }\n","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Log/src/Model/Table/ActionsTable.php#L109-L145","documentation":"ActionsTable::create() throws this ValidationException when the Action entity built via buildEntity() fails its validation rules before any save is attempted. It means the supplied action data (e.g. name) violates the table's validation ruleset.","triggerScenarios":"findOrCreateAction() receives an action name that is empty, exceeds the column length, or has an invalid type, so buildEntity() produces an entity with errors immediately.","commonSituations":"Plugin code logging actions with a null or '' name; action names longer than the varchar limit after a rename; passing non-scalar data (array/object) where a string name is expected; locale/encoding issues with very long translated action strings.","solutions":["Inspect $action->getErrors() (included in the ValidationException) to see which field failed.","Ensure the action name passed to findOrCreateAction()/create() is a non-empty string within the column length limit.","Check that the action context (context/name) matches what the validation rules expect.","Add a rule to the validation validator if legitimate data is being rejected by an overly strict rule."],"exampleFix":"// before\n$this->getService(ActionLogsService::class)->create(...);\n// after\n// ensure action name is valid before reaching the table\nif (!is_string($name) || $name === '') {\n    throw new BadRequestException('Action name must be a non-empty string.');\n}","handlingStrategy":"validation","validationCode":"if (!is_string($name) || trim($name) === '') { throw new \\InvalidArgumentException('Action name must be a non-empty string'); }","typeGuard":"function isValidActionName(mixed $name): bool { return is_string($name) && trim($name) !== '' && mb_strlen($name) <= 255; }","tryCatchPattern":"try { $action = $actionsTable->create($data); } catch (ValidationException $e) { $errors = $e->getEntity()->getErrors(); // inspect and correct payload\n}","preventionTips":["Use findOrCreateAction() rather than raw create() for action logging.","Log validation errors on first occurrence to catch regressions early.","Keep action name constants centralized to avoid drift.","Write tests asserting your action payloads validate."],"tags":["validation","logging","entity","cakephp"],"backgroundTag":"schema-validation-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"}