{"record":{"id":"1c16439b93c40165","repo":"Leantime/leantime","slug":"32602-1c1643","errorCode":"-32602","errorMessage":"Client name not specified","messagePattern":"Client name not specified","errorType":"validation","errorClass":"Leantime\\Core\\Exceptions\\MissingParameterException","httpStatus":422,"severity":"error","filePath":"app/Domain/Clients/Services/Clients.php","lineNumber":230,"sourceCode":"    /**\n     * Creates a new client after validating it and checking for duplicates.\n     *\n     * Encapsulates the name-required validation and the duplicate-name check\n     * that previously lived in the controller.\n     *\n     * @param  array  $values  Client data to create (requires a non-empty 'name')\n     * @return int Id of the newly created client\n     *\n     * @throws MissingParameterException When the client name is empty\n     * @throws EntityExistsException When a client with the same name/street already exists\n     *\n     * @api\n     */\n    #[RequiresPermission(ClientsPermissions::CREATE, global: true)]\n    public function createClient(array $values): int\n    {\n        if (($values['name'] ?? '') === '') {\n            throw new MissingParameterException('Client name not specified');\n        }\n\n        if ($this->isClient($values) === true) {\n            throw new EntityExistsException('Client exists already');\n        }\n\n        return (int) $this->clientRepository->addClient($values);\n    }\n\n    /**\n     * Updates an existing client after validating the name is present.\n     *\n     * @param  array  $values  Client data including 'id' key (requires a non-empty 'name')\n     * @return bool Returns true on success, false on failure\n     *\n     * @throws MissingParameterException When the client name is empty\n     *\n     * @api","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/Leantime/leantime/blob/9a9f49f1008f4782b30f6723c54228f4f992e636/app/Domain/Clients/Services/Clients.php#L212-L248","documentation":"Thrown by Clients::createClient() (JSON-RPC: leantime.rpc.Clients.Clients.createClient) when the $values array has no 'name' key or an empty-string name. The strict check ($values['name'] ?? '') === '' runs after the ClientsPermissions::CREATE gate, so an authorized caller still fails validation. Leantime maps MissingParameterException to JSON-RPC code -32602 (Invalid params).","triggerScenarios":"Calling createClient with {values: {}} or {values: {name: \"\"}}; submitting the new-client form with a blank name field; sending the name under a different key ('clientName', 'title') because the payload was copied from another schema.","commonSituations":"Optional form fields where the user can skip the name; integration scripts that map fields 1:1 from an external system and drop 'name'; whitespace-padded input (note: only exactly '' fails — ' ' passes this check but may cause duplicates).","solutions":["Include a non-empty string under values.name in the createClient payload","Validate and require the name field (trim whitespace) in the form or API client before calling createClient","Catch MissingParameterException (JSON-RPC -32602) and surface it as a field-level validation error instead of a generic failure"],"exampleFix":"// before (JSON-RPC request)\n{\"jsonrpc\":\"2.0\",\"method\":\"leantime.rpc.Clients.Clients.createClient\",\"params\":{\"values\":{\"street\":\"1 Main St\"}},\"id\":1}\n\n// after\n{\"jsonrpc\":\"2.0\",\"method\":\"leantime.rpc.Clients.Clients.createClient\",\"params\":{\"values\":{\"name\":\"Acme Corp\",\"street\":\"1 Main St\"}},\"id\":1}","handlingStrategy":"validation","validationCode":"$name = trim((string) ($values['name'] ?? ''));\nif ($name === '') {\n    // refuse before the API call; createClient requires a non-empty name\n    throw new \\InvalidArgumentException('values.name is required');\n}","typeGuard":"/** @param array $values @phpstan-assert array{name: non-empty-string} $values */\nfunction hasClientName(array $values): bool\n{\n    return is_string($values['name'] ?? null) && trim($values['name']) !== '';\n}","tryCatchPattern":"try {\n    $id = $clientsService->createClient($values);\n} catch (\\Leantime\\Core\\Exceptions\\MissingParameterException $e) {\n    // JSON-RPC -32602: show a field-level 'name is required' error\n    $errors['name'] = $e->getMessage();\n}","preventionTips":["Make the client name a required form field validated (with trim) client-side and server-side before calling createClient","When mapping payloads from external schemas, assert the 'name' key exists and is non-empty before sending","Treat JSON-RPC -32602 responses as payload bugs to fix at the call site, not server faults"],"tags":["clients","validation","json-rpc","missing-parameter","api"],"backgroundTag":"missing-required-parameter","analyzedSha":"9a9f49f1008f4782b30f6723c54228f4f992e636","analyzedAt":"2026-08-21T02:37:38.966Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}