passbolt/passbolt_api · error

$e->getMessage()

Error message

$e->getMessage()

What it means

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.

Solutions

  1. Read the printed exception message and verify LDAP host, port, and bind credentials in the directory sync configuration.
  2. Test connectivity from the passbolt host (e.g. ldapsearch or openssl s_client to the LDAP server).
  3. Confirm a default directory server is enabled and its settings validate in the admin UI.
  4. Re-run `bin/cake passbolt directory_sync test` after fixing config.
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check LDAP connectivity before running the command
$f = @fsockopen($host, $port, $errno, $errstr, 5);
if (!$f) { die("Cannot reach LDAP server: $errstr\n"); }
close: fclose($f);

Type guard

if (!is_array($directoryResults) || !method_exists($ldapDirectory, 'fetchDirectoryData')) { /* misconfiguration */ }

Try / catch

try {
    $directoryResults = $ldapDirectory->fetchDirectoryData();
} catch (\Exception $e) {
    $io->err('Directory sync test failed: ' . $e->getMessage());
    return $this->errorCode();
}

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Understand the failure class

Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.

Related errors


AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17). Data as JSON: /api/errors/0a734b3597ec0536. Report an issue: GitHub.

Appendix: source

Thrown at plugins/PassboltEe/DirectorySync/src/Command/TestCommand.php:54

    }

    /**
     * @inheritDoc
     */
    public function execute(Arguments $args, ConsoleIo $io): ?int
    {
        parent::execute($args, $io);

        try {
            $directoryOrgSettings = DirectoryOrgSettings::get();
            $ldapDirectory = new LdapDirectory($directoryOrgSettings);
            $directoryResults = $ldapDirectory->fetchDirectoryData();
            $data = [
                'users' => array_values($directoryResults->getUsers()),
                'groups' => array_values($directoryResults->getGroups()),
            ];
        } catch (Exception $e) {
             $io->err($e->getMessage());

            return $this->errorCode();
        }

        $this->displayEntries($data, $io);

        $tree = $ldapDirectory->getFilteredDirectoryResults()->getFlattenedTree();
        $this->displayFlattenedTree($tree, $io);

        $data['users'] = $directoryResults->getInvalidUsers();
        $data['groups'] = $directoryResults->getInvalidGroups();
        $this->displayInvalidEntries($data, $io);

        return $this->successCode();
    }

    /**
     * Display flattened tree.

View on GitHub (pinned to 31c1bbc10f)