{"record":{"id":"0a734b3597ec0536","repo":"passbolt/passbolt_api","slug":"e-getmessage-testcommand","errorCode":null,"errorMessage":"$e->getMessage()","messagePattern":"\\$e->getMessage\\(\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/PassboltEe/DirectorySync/src/Command/TestCommand.php","lineNumber":54,"sourceCode":"    }\n\n    /**\n     * @inheritDoc\n     */\n    public function execute(Arguments $args, ConsoleIo $io): ?int\n    {\n        parent::execute($args, $io);\n\n        try {\n            $directoryOrgSettings = DirectoryOrgSettings::get();\n            $ldapDirectory = new LdapDirectory($directoryOrgSettings);\n            $directoryResults = $ldapDirectory->fetchDirectoryData();\n            $data = [\n                'users' => array_values($directoryResults->getUsers()),\n                'groups' => array_values($directoryResults->getGroups()),\n            ];\n        } catch (Exception $e) {\n             $io->err($e->getMessage());\n\n            return $this->errorCode();\n        }\n\n        $this->displayEntries($data, $io);\n\n        $tree = $ldapDirectory->getFilteredDirectoryResults()->getFlattenedTree();\n        $this->displayFlattenedTree($tree, $io);\n\n        $data['users'] = $directoryResults->getInvalidUsers();\n        $data['groups'] = $directoryResults->getInvalidGroups();\n        $this->displayInvalidEntries($data, $io);\n\n        return $this->successCode();\n    }\n\n    /**\n     * Display flattened tree.","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/DirectorySync/src/Command/TestCommand.php#L36-L72","documentation":"DirectorySync TestCommand::execute fetches directory data over LDAP to preview what a sync would do. If any Exception is thrown during fetchDirectoryData (connection failure, bind failure, bad config), the raw exception message is printed via $io->err and the command exits with an error code. The message text varies with the underlying LDAP exception.","triggerScenarios":"`bin/cake passbolt directory_sync test` when the LDAP connection cannot be established, credentials/bind fail, or the configured base DN/search is invalid, causing LdapDirectory->fetchDirectoryData() to throw.","commonSituations":"Wrong LDAP host/port in passbolt.php, expired service account password, TLS/certificate mismatch, firewall blocking the LDAP port, or directory servers configured but no default server selected.","solutions":["Read the printed exception message and verify LDAP host, port, and bind credentials in the directory sync configuration.","Test connectivity from the passbolt host (e.g. ldapsearch or openssl s_client to the LDAP server).","Confirm a default directory server is enabled and its settings validate in the admin UI.","Re-run `bin/cake passbolt directory_sync test` after fixing config."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check LDAP connectivity before running the command\n$f = @fsockopen($host, $port, $errno, $errstr, 5);\nif (!$f) { die(\"Cannot reach LDAP server: $errstr\\n\"); }\nclose: fclose($f);","typeGuard":"if (!is_array($directoryResults) || !method_exists($ldapDirectory, 'fetchDirectoryData')) { /* misconfiguration */ }","tryCatchPattern":"try {\n    $directoryResults = $ldapDirectory->fetchDirectoryData();\n} catch (\\Exception $e) {\n    $io->err('Directory sync test failed: ' . $e->getMessage());\n    return $this->errorCode();\n}","preventionTips":["Validate LDAP host/port/bind credentials in config before running","Enable a default directory server in admin UI","Test network reachability (ldapsearch) from the passbolt host","Check TLS certificate validity"],"tags":["cli","ldap","directory-sync","connection"],"backgroundTag":"connection-refused","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"}