{"record":{"id":"3338c48149700343","repo":"passbolt/passbolt_api","slug":"an-error-has-occurred-parsing-usercustomfilter-pe-getmessage","errorCode":null,"errorMessage":"An error has occurred parsing userCustomFilter: {pe->getMessage()}","messagePattern":"An error has occurred parsing userCustomFilter: (.+?)","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"plugins/PassboltEe/DirectorySync/src/Utility/LdapDirectory.php","lineNumber":560,"sourceCode":"     *\n     * @param \\LdapRecord\\Query\\Builder $query query\n     * @return \\LdapRecord\\Query\\Builder\n     * @throws \\InvalidArgumentException If userCustomFilter callback is used.\n     * @throws \\InvalidArgumentException If userCustomFilter cannot be parsed.\n     */\n    private function _customizeUsersQuery(Builder $query): Builder\n    {\n        $userCustomFilter = $this->directorySettings->getUserCustomFilters();\n        if (is_callable($userCustomFilter)) {\n            throw new InvalidArgumentException(\n                'Using callbacks for userCustomFilter is not supported anymore. Please use LDAP search filter instead.'\n            );\n        } elseif (is_string($userCustomFilter)) {\n            try {\n                $filter = Parser::parse($userCustomFilter);\n                $query->rawFilter(Parser::assemble($filter));\n            } catch (ParserException $pe) {\n                throw new InvalidArgumentException(\n                    'An error has occurred parsing userCustomFilter: ' . $pe->getMessage()\n                );\n            }\n        }\n\n        return $query;\n    }\n\n    /**\n     * Customize groups query as per configuration (if available).\n     *\n     * @param \\LdapRecord\\Query\\Builder $query query\n     * @return \\LdapRecord\\Query\\Builder\n     * @throws \\InvalidArgumentException If groupCustomFilter callback is used.\n     * @throws \\InvalidArgumentException If groupCustomFilter cannot be parsed.\n     */\n    private function _customizeGroupsQuery(Builder $query): Builder\n    {","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/DirectorySync/src/Utility/LdapDirectory.php#L542-L578","documentation":"When userCustomFilter is a string, it is parsed as an LDAP search filter with LdapTools' Parser. If the string is not a syntactically valid LDAP filter, the ParserException is caught and rethrown as an InvalidArgumentException with the parser's message appended, explaining that the custom filter could not be parsed.","triggerScenarios":"Calling _fetchAndInitializeUsersQuery when directorySettings->getUserCustomFilters() returns a malformed string filter, causing Parser::parse() to throw.","commonSituations":"Hand-written LDAP filter with unbalanced parentheses, missing attribute/value, or wrong escaping (e.g. '(objectClass=user' or '(&(objectClass=user)(department=IT))' typos) entered in directory sync settings.","solutions":["Read the appended ParserException message to locate the syntax problem","Fix the userCustomFilter string to be a valid RFC 4515 LDAP filter with balanced parentheses and proper escaping","Validate the filter against the LDAP directory (e.g. ldapsearch with the same filter) before saving it in settings"],"exampleFix":"// before\n$userCustomFilter = '(objectClass=user';\n// after\n$userCustomFilter = '(objectClass=user)';","handlingStrategy":"validation","validationCode":"try {\n    $parsed = \\LdapTools\\Query\\Builder::parse($userCustomFilter); // or Parser::parse\n} catch (ParserException $e) {\n    // abort before sync\n}","typeGuard":null,"tryCatchPattern":"try {\n    $result = $sync->run();\n} catch (InvalidArgumentException $e) {\n    if (str_starts_with($e->getMessage(), 'An error has occurred parsing userCustomFilter')) {\n        // fix settings, surface to admin\n    }\n}","preventionTips":["Validate LDAP filters with ldapsearch before storing them","Keep a small set of reviewed filter templates","Escape parentheses and special chars in attribute values"],"tags":["ldap","directory-sync","filter-parsing","configuration"],"backgroundTag":"invalid-regex-pattern","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"}