{"record":{"id":"8e5893c487f0b868","repo":"passbolt/passbolt_api","slug":"500-the-value-should-be-an-array","errorCode":"500","errorMessage":"The value should be an array","messagePattern":"The value should be an array","errorType":"exception","errorClass":"InternalErrorException","httpStatus":500,"severity":"error","filePath":"plugins/PassboltEe/MfaPolicies/src/Service/MfaPoliciesGetSettingsService.php","lineNumber":45,"sourceCode":"    use LocatorAwareTrait;\n\n    /**\n     * Returns MFA policies settings.\n     *\n     * @return \\Passbolt\\MfaPolicies\\Model\\Dto\\MfaPolicySettings\n     * @throws \\Cake\\Http\\Exception\\InternalErrorException When value is not an array.\n     */\n    public function get(): MfaPolicySettings\n    {\n        /** @var \\Passbolt\\MfaPolicies\\Model\\Table\\MfaPoliciesSettingsTable $mfaPoliciesSettingsTable */\n        $mfaPoliciesSettingsTable = $this->fetchTable('Passbolt/MfaPolicies.MfaPoliciesSettings');\n\n        /** @var \\Passbolt\\MfaPolicies\\Model\\Entity\\MfaPoliciesSetting|null $mfaPoliciesSettings */\n        $mfaPoliciesSettings = $mfaPoliciesSettingsTable->find()->first();\n\n        if ($mfaPoliciesSettings !== null) {\n            if (!is_array($mfaPoliciesSettings->value)) {\n                throw new InternalErrorException('The value should be an array');\n            }\n\n            return MfaPolicySettings::createFromEntity($mfaPoliciesSettings);\n        }\n\n        // Set default options\n        $mfaPoliciesSettings = [\n            'policy' => MfaPoliciesSetting::POLICY_OPT_IN,\n            'remember_me_for_a_month' => true,\n        ];\n\n        return MfaPolicySettings::createFromArray($mfaPoliciesSettings);\n    }\n}\n","sourceCodeStart":27,"sourceCodeEnd":60,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/MfaPolicies/src/Service/MfaPoliciesGetSettingsService.php#L27-L60","documentation":"MfaPoliciesGetSettingsService::get() expects the mfa_policies_settings 'value' column (serialized by the table layer) to be an array. If the stored entity's value is not an array — typically corrupted or legacy data that bypassed serialization — it throws InternalErrorException (500) rather than returning malformed settings.","triggerScenarios":"Reading MFA policy settings when the mfa_policies_settings table row's value column holds a non-array (e.g. raw string/null that wasn't json_decoded, manually edited DB row).","commonSituations":"Manual database edits or imports, restoring settings from a backup of a different schema version, or a bug writing the value column.","solutions":["Inspect the mfa_policies_settings row and fix its value column to contain a valid JSON object/array like {\"policy\":\"mandatory\"}","Delete the corrupt row so the service falls back to default settings, then re-save settings via the admin UI","Check the MfaPoliciesSetting entity/table serialization config to ensure value is json-encoded on save"],"exampleFix":"// before\nUPDATE mfa_policies_settings SET value = 'mandatory';\n// after\nUPDATE mfa_policies_settings SET value = '{\"policy\":\"mandatory\"}';","handlingStrategy":"try-catch","validationCode":"$row = TableRegistry::getTableLocator()->get('Passbolt/MfaPolicies.MfaPoliciesSetting')->find()->first();\nif ($row !== null && !is_array(json_decode((string)$row->value, true))) {\n    // corrupt data, reset before calling get()\n}","typeGuard":"$value = json_decode((string)$row->value, true);\n$isSettingsArray = is_array($value) && isset($value['policy']);","tryCatchPattern":"try {\n    $settings = (new MfaPoliciesGetSettingsService())->get();\n} catch (InternalErrorException $e) {\n    if ($e->getMessage() === 'The value should be an array') {\n        // reset mfa_policies_settings row, fall back to defaults\n    }\n}","preventionTips":["Never hand-edit the value column; use the settings API","Keep entity JSON serialization intact across migrations","Validate backups/restores against the current schema"],"tags":["mfa-policies","data-corruption","internal-error","database"],"backgroundTag":"type-mismatch","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"}