moodle/moodle · error · moodle_exception

agedigitalconsentmapinvalidage

agedigitalconsentmapinvalidage

Error message

agedigitalconsentmapinvalidage

What it means

This Moodle exception is thrown by auth's parse_age_digital_consent_map() when an entry in the age digital consent map (a 'country:age' list configured per auth plugin) has an age value that is not numeric. The method parses each mapping and requires the age part to pass is_numeric(); if not, it aborts parsing because a non-numeric consent age would make is_minor() meaningless. It is a config-data validation error, not a runtime failure.

Solutions

  1. Open the age digital consent map setting and inspect every line; the offending value is included in the exception's data ($a).
  2. Correct the age to a plain integer (e.g. 'DE:16', 'FR:15').
  3. Ensure every line uses the expected country:age format and that the '*' default line also has a numeric age.
  4. Re-test is_minor() / the signup flow to confirm parsing succeeds.

Example fix

// before (map config)
DE:seventeen
FR:15
*:16
// after
DE:17
FR:15
*:16
Defensive patterns

Strategy: validation

Validate before calling

$map = get_config('auth_yourplugin', 'agedigitalconsentmap');
foreach (explode(',', $map) as $entry) {
    [$country, $age] = array_map('trim', explode(':', $entry, 2));
    if (!is_numeric($age)) {
        throw new InvalidArgumentException("Non-numeric consent age for country '{$country}': '{$age}'");
    }
}

Type guard

function is_valid_consent_map_entry(string $entry): bool {
    $parts = array_map('trim', explode(':', $entry, 2));
    return count($parts) === 2 && is_numeric($parts[1]);
}

Try / catch

try {
    $isMinor = \core_auth\digital_consent::is_minor($age, $country);
} catch (\moodle_exception $e) {
    if ($e->errorcode === 'agedigitalconsentmapinvalidage') {
        debugging('Fix the age digital consent map: ' . $e->debuginfo, DEBUG_DEVELOPER);
    }
    throw $e;
}

Prevention

When it happens

Trigger: Calling is_minor() (which calls parse_age_digital_consent_map) when the configured age digital consent map contains a line whose age component is non-numeric, e.g. 'DE: sixteen', 'FR:', or contains stray characters like 'FR:16a'. Also triggered when a malformed delimiter puts the wrong token in the age position.

Common situations: Admins hand-editing the digital consent age map in site config or plugin settings and typo-ing the age; copy-pasting maps from docs where the delimiter differs so country/age split incorrectly; locale settings where commas ('16,5') sneak into the age field.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14). Data as JSON: /api/errors/f8254057c13ca44b. Report an issue: GitHub.

Appendix: source

Thrown at public/auth/classes/digital_consent.php:95

        foreach ($lines as $line) {
            $arr = explode(",", $line);
            // Handle if there is more or less than one comma separator.
            if (count($arr) != 2) {
                throw new \moodle_exception('agedigitalconsentmapinvalidcomma', 'error', '', $line);
            }
            $country = trim($arr[0]);
            $age = trim($arr[1]);
            // Check if default.
            if ($country == "*") {
                $isdefaultvaluepresent = true;
            }
            // Handle if the presented value for country is not valid.
            if ($country !== "*" && !array_key_exists($country, $countries)) {
                throw new \moodle_exception('agedigitalconsentmapinvalidcountry', 'error', '', $country);
            }
            // Handle if the presented value for age is not valid.
            if (!is_numeric($age)) {
                throw new \moodle_exception('agedigitalconsentmapinvalidage', 'error', '', $age);
            }
            $ageconsentmapparsed[$country] = $age;
        }
        // Handle if a default value does not exist.
        if (!$isdefaultvaluepresent) {
            throw new \moodle_exception('agedigitalconsentmapinvaliddefault');
        }

        return $ageconsentmapparsed;
    }
}

View on GitHub (pinned to 48ea8c3322)