{"record":{"id":"6401757296aad189","repo":"phalcon/cphalcon","slug":"route-config-entry-is-missing-pattern","errorCode":null,"errorMessage":"Route config entry is missing 'pattern'","messagePattern":"Route config entry is missing 'pattern'","errorType":"exception","errorClass":"Phalcon\\Mvc\\Router\\Exceptions\\MissingRouteConfigKey","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Router.zep","lineNumber":2061,"sourceCode":"     */\n    public function wasMatched() -> bool\n    {\n        return this->wasMatched;\n    }\n\n    /**\n     * Adds a single route from a config array entry. Used by loadFromConfig.\n     *\n     * @param array routeData\n     *\n     * @return void\n     */\n    protected function addRouteFromConfig(array routeData) -> void\n    {\n        var method, methodClass, pattern, paths, route;\n\n        if !fetch pattern, routeData[\"pattern\"] {\n            throw new MissingRouteConfigKey(\"pattern\");\n        }\n\n        if !fetch paths, routeData[\"paths\"] {\n            throw new MissingRouteConfigKey(\"paths\");\n        }\n\n        let method = \"\";\n        if isset routeData[\"method\"] && routeData[\"method\"] !== null {\n            let method = strtolower((string) routeData[\"method\"]);\n        }\n\n        switch method {\n            case \"\":\n            case \"connect\":\n            case \"delete\":\n            case \"get\":\n            case \"head\":\n            case \"options\":","sourceCodeStart":2043,"sourceCodeEnd":2079,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Router.zep#L2043-L2079","documentation":"While processing entries from config['routes'] (via loadFromConfig -> addRouteFromConfig), each entry must contain a 'pattern' key defining the URI pattern to match. If the first fetch of routeData['pattern'] fails (key absent or null), MissingRouteConfigKey('pattern') is thrown naming the missing key.","triggerScenarios":"A route entry like {\"paths\": {\"controller\": \"users\"}} with no \"pattern\"; pattern misspelled (\"patterns\", \"route\", \"uri\"); entry reduced to an empty object by a merge or an if-block that never set it.","commonSituations":"Hand-written YAML/JSON route files with inconsistent keys; config templates where the pattern line was commented out; code generators emitting a subset of keys.","solutions":["Add the pattern: {\"pattern\": \"/api/users\", \"paths\": {\"controller\": \"users\", \"action\": \"index\"}}","Check spelling of the key — it must be exactly 'pattern' (lowercase)","Pre-validate every routes[] entry contains both 'pattern' and 'paths' before loadFromConfig so the error names the file and index"],"exampleFix":"// before\n{\n    \"routes\": [\n        {\"paths\": {\"controller\": \"users\", \"action\": \"index\"}}\n    ]\n}\n\n// after\n{\n    \"routes\": [\n        {\n            \"pattern\": \"/api/users\",\n            \"paths\": {\"controller\": \"users\", \"action\": \"index\"}\n        }\n    ]\n}","handlingStrategy":"validation","validationCode":"// verify required keys per route entry before loading\nforeach ($config['routes'] ?? [] as $i => $entry) {\n    if (!is_array($entry) || !array_key_exists('pattern', $entry)) {\n        throw new InvalidArgumentException(\"routes[$i] is missing 'pattern'\");\n    }\n    if (!array_key_exists('paths', $entry)) {\n        throw new InvalidArgumentException(\"routes[$i] is missing 'paths'\");\n    }\n}\n\n$router->loadFromConfig($config);","typeGuard":"function routeEntryIsValid(mixed $entry): bool\n{\n    return is_array($entry)\n        && array_key_exists('pattern', $entry)\n        && array_key_exists('paths', $entry);\n}","tryCatchPattern":"try {\n    $router->loadFromConfig($config);\n} catch (\\Phalcon\\Mvc\\Router\\Exceptions\\MissingRouteConfigKey $e) {\n    // message names the missing key ('pattern' or 'paths')\n    $logger->error('Route config entry rejected: ' . $e->getMessage());\n    throw $e;\n}","preventionTips":["Make 'pattern' and 'paths' mandatory fields in your routes-file template","Validate the routes file with a schema checker in CI","When generating routes in code, build entries via a factory that always sets both keys"],"tags":["phalcon","router","config","route-definition","validation"],"backgroundTag":"invalid-route-configuration","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}