{"record":{"id":"f8254057c13ca44b","repo":"moodle/moodle","slug":"agedigitalconsentmapinvalidage","errorCode":"agedigitalconsentmapinvalidage","errorMessage":"agedigitalconsentmapinvalidage","messagePattern":"agedigitalconsentmapinvalidage","errorType":"validation","errorClass":"moodle_exception","httpStatus":null,"severity":"error","filePath":"public/auth/classes/digital_consent.php","lineNumber":95,"sourceCode":"        foreach ($lines as $line) {\n            $arr = explode(\",\", $line);\n            // Handle if there is more or less than one comma separator.\n            if (count($arr) != 2) {\n                throw new \\moodle_exception('agedigitalconsentmapinvalidcomma', 'error', '', $line);\n            }\n            $country = trim($arr[0]);\n            $age = trim($arr[1]);\n            // Check if default.\n            if ($country == \"*\") {\n                $isdefaultvaluepresent = true;\n            }\n            // Handle if the presented value for country is not valid.\n            if ($country !== \"*\" && !array_key_exists($country, $countries)) {\n                throw new \\moodle_exception('agedigitalconsentmapinvalidcountry', 'error', '', $country);\n            }\n            // Handle if the presented value for age is not valid.\n            if (!is_numeric($age)) {\n                throw new \\moodle_exception('agedigitalconsentmapinvalidage', 'error', '', $age);\n            }\n            $ageconsentmapparsed[$country] = $age;\n        }\n        // Handle if a default value does not exist.\n        if (!$isdefaultvaluepresent) {\n            throw new \\moodle_exception('agedigitalconsentmapinvaliddefault');\n        }\n\n        return $ageconsentmapparsed;\n    }\n}\n","sourceCodeStart":77,"sourceCodeEnd":107,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/auth/classes/digital_consent.php#L77-L107","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Open the age digital consent map setting and inspect every line; the offending value is included in the exception's data ($a).","Correct the age to a plain integer (e.g. 'DE:16', 'FR:15').","Ensure every line uses the expected country:age format and that the '*' default line also has a numeric age.","Re-test is_minor() / the signup flow to confirm parsing succeeds."],"exampleFix":"// before (map config)\nDE:seventeen\nFR:15\n*:16\n// after\nDE:17\nFR:15\n*:16","handlingStrategy":"validation","validationCode":"$map = get_config('auth_yourplugin', 'agedigitalconsentmap');\nforeach (explode(',', $map) as $entry) {\n    [$country, $age] = array_map('trim', explode(':', $entry, 2));\n    if (!is_numeric($age)) {\n        throw new InvalidArgumentException(\"Non-numeric consent age for country '{$country}': '{$age}'\");\n    }\n}","typeGuard":"function is_valid_consent_map_entry(string $entry): bool {\n    $parts = array_map('trim', explode(':', $entry, 2));\n    return count($parts) === 2 && is_numeric($parts[1]);\n}","tryCatchPattern":"try {\n    $isMinor = \\core_auth\\digital_consent::is_minor($age, $country);\n} catch (\\moodle_exception $e) {\n    if ($e->errorcode === 'agedigitalconsentmapinvalidage') {\n        debugging('Fix the age digital consent map: ' . $e->debuginfo, DEBUG_DEVELOPER);\n    }\n    throw $e;\n}","preventionTips":["Always use plain integers for ages in the consent map.","Validate the map string at the point where the setting is saved.","Keep the 'country:age' delimiter consistent; avoid locale-specific decimal separators.","Test is_minor() for a listed and an unlisted country after any map edit."],"tags":["config","validation","consent","age-map"],"backgroundTag":"invalid-config-value","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}