{"record":{"id":"f3f29a9853872f79","repo":"passbolt/passbolt_api","slug":"directory-settings-are-invalid-please-check-your-config-and","errorCode":null,"errorMessage":"Directory Settings are invalid. Please check your config and try again.","messagePattern":"Directory Settings are invalid\\. Please check your config and try again\\.","errorType":"exception","errorClass":"UnexpectedValueException","httpStatus":500,"severity":"error","filePath":"plugins/PassboltEe/DirectorySync/src/Service/DirectorySettings/UpdateDirectorySettingsService.php","lineNumber":51,"sourceCode":"     */\n    public function updateSettings(): void\n    {\n        /** @var \\App\\Model\\Table\\OrganizationSettingsTable $OrganizationSettings */\n        $OrganizationSettings = $this->fetchTable('OrganizationSettings');\n        /** @var \\App\\Model\\Entity\\OrganizationSetting|null $directorySyncSettings */\n        $directorySyncSettings = $OrganizationSettings\n            ->find()\n            ->where([\n                'property' => DirectoryOrgSettings::ORG_SETTINGS_PROPERTY,\n            ])->first();\n\n        if (!$directorySyncSettings) {\n            return;\n        }\n\n        $value = json_decode($directorySyncSettings['value'], true);\n        if (!$value || !is_array($value)) {\n            throw new UnexpectedValueException(\n                __('Directory Settings are invalid. Please check your config and try again.')\n            );\n        }\n        // set the new key for list of servers/hosts in the new library\n        if (is_array($value['ldap']['domains'])) {\n            foreach ($value['ldap']['domains'] as $domain => $config) {\n                if (array_key_exists('servers', $config)) {\n                    $value['ldap']['domains'][$domain]['hosts'] = $config['servers'];\n                    unset($value['ldap']['domains'][$domain]['servers']);\n                }\n            }\n        }\n\n        // keep compatibility with old library default class value\n        if (empty($value['groupObjectClass'])) {\n            $value['groupObjectClass'] = 'groupOfNames';\n        }\n        $value['enabled'] = false;","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/DirectorySync/src/Service/DirectorySettings/UpdateDirectorySettingsService.php#L33-L69","documentation":"UpdateDirectorySettingsService::updateSettings() migrates old (v3-format) directory sync organization settings to the v4 format (renaming ldap.domains.*.servers to hosts, etc.). It first json_decodes the stored settings value and throws this UnexpectedValueException if the result is empty, false (invalid JSON), or not an array — i.e. the stored settings cannot be parsed into the expected structure.","triggerScenarios":"Running the settings update during a v3→v4 upgrade when the organization_settings value column for directory sync contains invalid JSON, an empty string, or a scalar (e.g. '0', 'null', serialized-but-not-JSON data).","commonSituations":"Upgraded passbolt where the settings row was written by a much older version in a different format; manual DB edits that broke the JSON; truncated value column; charset/encoding corruption during a DB dump/restore.","solutions":["Inspect the stored value: SELECT value FROM organization_settings WHERE property = 'directory-sync'; and validate it with json_decode.","Fix or regenerate the settings by re-saving LDAP configuration in the passbolt admin UI.","If unrecoverable, delete the settings row and reconfigure directory sync from scratch in v4.","Restore the row from a pre-upgrade backup if the corruption happened during migration."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"$raw = $settings->value;\n$decoded = json_decode($raw, true);\nif (!$decoded || !is_array($decoded)) { /* abort: invalid stored settings */ }","typeGuard":"$hasValidSettingsJson = fn(?OrganizationSetting $s): bool => $s && ($v = json_decode($s->value, true)) && is_array($v);","tryCatchPattern":"try {\n    (new UpdateDirectorySettingsService())->updateSettings();\n} catch (UnexpectedValueException $e) {\n    // stored value is not valid JSON — restore from backup or reconfigure LDAP settings\n}","preventionTips":["Validate the stored JSON before running upgrade/migration services","Back up organization_settings before v3→v4 upgrades","Re-save directory sync settings via the admin UI rather than editing the DB","Check value column integrity (truncation/charset) after DB restores"],"tags":["passbolt","directory-sync","organization-settings","json-decode","upgrade"],"backgroundTag":"json-decode-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"}