flarum/framework · error · ValidationException

Invalid erasure mode: $mode

Error message

Invalid erasure mode: $mode

What it means

UserResourceDeleteEndpoint::deleteAction reads the erasure mode from gdprMode in the request body (falling back to the flarum-gdpr.default-erasure setting) and throws a ValidationException if it is not one of the allowed modes (anonymization or deletion).

Solutions

  1. Send gdprMode exactly as 'anonymization' or 'deletion' (use ErasureRequest::MODE_* constants).
  2. Fix the flarum-gdpr.default-erasure setting in the admin panel/database if the fallback is invalid.
  3. Check for case-sensitivity and trailing whitespace in the submitted mode value.

Example fix

// before
{ "gdprMode": "delete" }
// after
{ "gdprMode": "deletion" }
Defensive patterns

Strategy: validation

Validate before calling

$mode = $body['gdprMode'] ?? $settings->get('flarum-gdpr.default-erasure'); if (! in_array($mode, [ErasureRequest::MODE_ANONYMIZATION, ErasureRequest::MODE_DELETION], true)) { /* reject before sending */ }

Try / catch

try { $api->deleteUser($id, ['gdprMode' => $mode]); } catch (ValidationException $e) { // inspect $e->getErrors()['mode'] }

Prevention

When it happens

Trigger: Deleting a user via the GDPR delete endpoint with body gdprMode set to anything other than 'anonymization'/'deletion', or with an invalid stored value in the flarum-gdpr.default-erasure setting and no gdprMode supplied.

Common situations: Client sending gdprMode: 'delete' or 'erase' instead of the exact mode strings; admin misconfiguring default-erasure in settings; casing/typos in the mode value.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of flarum/framework@4b939f6853 (2026-09-15). Data as JSON: /api/errors/353fe5101a4235f3. Report an issue: GitHub.

Appendix: source

Thrown at extensions/gdpr/src/Api/UserResourceDeleteEndpoint.php:61

            $this->deleteAction($model, $context);

            $endpoint->callAfterHook($context, $model);

            return null;
        });
    }

    /**
     * @throws ValidationException
     */
    protected function deleteAction(User $user, Context $context): void
    {
        $actor = $context->getActor();
        $mode = Arr::get($context->body(), 'gdprMode', $this->settings->get('flarum-gdpr.default-erasure'));

        if (! in_array($mode, [ErasureRequest::MODE_ANONYMIZATION, ErasureRequest::MODE_DELETION])) {
            throw new ValidationException(['mode' => "Invalid erasure mode: $mode"]);
        }

        ErasureRequest::unguard();

        $erasureRequest = ErasureRequest::firstOrNew([
            'user_id' => $user->id,
        ]);

        $erasureRequest->user_id = $user->id;
        $erasureRequest->status = ErasureRequest::STATUS_MANUAL;
        $erasureRequest->created_at = Carbon::now();
        $erasureRequest->processed_mode = $mode;
        $erasureRequest->processed_at = Carbon::now();
        $erasureRequest->processed_by = $actor->id;

        $erasureRequest->save();

        ErasureRequest::reguard();

View on GitHub (pinned to 4b939f6853)