passbolt/passbolt_api · error · InternalErrorException

500

500

Error message

The value should be an array

What it means

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.

Solutions

  1. Inspect the mfa_policies_settings row and fix its value column to contain a valid JSON object/array like {"policy":"mandatory"}
  2. Delete the corrupt row so the service falls back to default settings, then re-save settings via the admin UI
  3. Check the MfaPoliciesSetting entity/table serialization config to ensure value is json-encoded on save

Example fix

// before
UPDATE mfa_policies_settings SET value = 'mandatory';
// after
UPDATE mfa_policies_settings SET value = '{"policy":"mandatory"}';
Defensive patterns

Strategy: try-catch

Validate before calling

$row = TableRegistry::getTableLocator()->get('Passbolt/MfaPolicies.MfaPoliciesSetting')->find()->first();
if ($row !== null && !is_array(json_decode((string)$row->value, true))) {
    // corrupt data, reset before calling get()
}

Type guard

$value = json_decode((string)$row->value, true);
$isSettingsArray = is_array($value) && isset($value['policy']);

Try / catch

try {
    $settings = (new MfaPoliciesGetSettingsService())->get();
} catch (InternalErrorException $e) {
    if ($e->getMessage() === 'The value should be an array') {
        // reset mfa_policies_settings row, fall back to defaults
    }
}

Prevention

When it happens

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

Common situations: Manual database edits or imports, restoring settings from a backup of a different schema version, or a bug writing the value column.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at plugins/PassboltEe/MfaPolicies/src/Service/MfaPoliciesGetSettingsService.php:45

    use LocatorAwareTrait;

    /**
     * Returns MFA policies settings.
     *
     * @return \Passbolt\MfaPolicies\Model\Dto\MfaPolicySettings
     * @throws \Cake\Http\Exception\InternalErrorException When value is not an array.
     */
    public function get(): MfaPolicySettings
    {
        /** @var \Passbolt\MfaPolicies\Model\Table\MfaPoliciesSettingsTable $mfaPoliciesSettingsTable */
        $mfaPoliciesSettingsTable = $this->fetchTable('Passbolt/MfaPolicies.MfaPoliciesSettings');

        /** @var \Passbolt\MfaPolicies\Model\Entity\MfaPoliciesSetting|null $mfaPoliciesSettings */
        $mfaPoliciesSettings = $mfaPoliciesSettingsTable->find()->first();

        if ($mfaPoliciesSettings !== null) {
            if (!is_array($mfaPoliciesSettings->value)) {
                throw new InternalErrorException('The value should be an array');
            }

            return MfaPolicySettings::createFromEntity($mfaPoliciesSettings);
        }

        // Set default options
        $mfaPoliciesSettings = [
            'policy' => MfaPoliciesSetting::POLICY_OPT_IN,
            'remember_me_for_a_month' => true,
        ];

        return MfaPolicySettings::createFromArray($mfaPoliciesSettings);
    }
}

View on GitHub (pinned to 31c1bbc10f)