{"record":{"id":"21f913f6c8ebbe49","repo":"phalcon/cphalcon","slug":"the-route-contains-invalid-paths-pattern","errorCode":null,"errorMessage":"The route contains invalid paths ('{pattern}')","messagePattern":"The route contains invalid paths \\('(.+?)'\\)","errorType":"exception","errorClass":"Phalcon\\Cli\\Router\\Exceptions\\InvalidRoutePaths","httpStatus":null,"severity":"error","filePath":"phalcon/Cli/Router/Route.zep","lineNumber":460,"sourceCode":"            let routePaths = [];\n\n            // Process module name\n            if moduleName !== null {\n                let routePaths[\"module\"] = moduleName;\n            }\n\n            // Process task name\n            if taskName !== null {\n                // Check if we need to obtain the namespace\n                if memstr(taskName, \"\\\\\") {\n                    // Extract the real class name from the namespaced class\n                    let realClassName = get_class_ns(taskName);\n\n                    // Extract the namespace from the namespaced class\n                    let namespaceName = get_ns_class(taskName);\n\n                    if unlikely (namespaceName === null || realClassName === null) {\n                        throw new InvalidRoutePaths(pattern);\n                    }\n\n                    // Update the namespace\n                    if namespaceName {\n                        let routePaths[\"namespace\"] = namespaceName;\n                    }\n                } else {\n                    let realClassName = taskName;\n                }\n\n                // Always pass the task to lowercase\n                let routePaths[\"task\"] = uncamelize(realClassName);\n            }\n\n            // Process action name\n            if actionName !== null {\n                let routePaths[\"action\"] = actionName;\n            }","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Cli/Router/Route.zep#L442-L478","documentation":"When a CLI route's paths define a namespaced task (task name containing a backslash), Phalcon splits it with get_class_ns()/get_ns_class() to derive the namespace and the bare task name. If either half comes back null — the string does not decompose into namespace + class name — InvalidRoutePaths is thrown with the route pattern.","triggerScenarios":"$router->add('/jobs', ['task' => '\\Tasks\\Main']) with a leading backslash, 'App\\Tasks\\' with a trailing backslash, or a lone '\\' — none decompose into a namespace plus a real class name.","commonSituations":"Copying fully-qualified class names with the leading \\ exactly as written in PHP source into route paths; concatenating namespace constants ('NS . '\\Tasks\\' style) that leave empty segments.","solutions":["Remove leading/trailing backslashes: ['task' => 'App\\Tasks\\Main']","Or specify namespace and task separately: ['namespace' => 'App\\Tasks', 'task' => 'main']","Keep task names un-namespaced and pass the namespace under its own 'namespace' path key"],"exampleFix":"// before\n$router->add('/jobs', ['task' => '\\App\\Tasks\\Main']);\n\n// after\n$router->add('/jobs', ['namespace' => 'App\\Tasks', 'task' => 'main']);","handlingStrategy":"validation","validationCode":"function assertValidTaskName(string $task): void\n{\n    if (strpos($task, '\\\\') !== false &&\n        !preg_match('/^[A-Za-z_][A-Za-z0-9_]*(\\\\[A-Za-z_][A-Za-z0-9_]*)+$/', $task)) {\n        throw new InvalidArgumentException('Malformed namespaced task: ' . $task);\n    }\n}\nassertValidTaskName($task);\n$router->add('/jobs', ['task' => $task]);","typeGuard":"/**\n * A namespaced task must decompose into namespace + class name:\n * no leading/trailing backslash, no empty segments.\n */\nfunction isDecomposableTaskName(string $task): bool\n{\n    return preg_match('/^[A-Za-z_][A-Za-z0-9_]*(\\\\[A-Za-z_][A-Za-z0-9_]*)+$/', $task) === 1;\n}","tryCatchPattern":"try {\n    $router->add($pattern, $paths);\n} catch (\\Phalcon\\Cli\\Router\\Route\\Exception\\InvalidRoutePaths $e) {\n    // Falls through when namespace/class extraction from the task name fails.\n    // Split 'App\\Tasks\\Main' into namespace + task keys and retry.\n    $parts = explode('\\\\', trim($paths['task'], '\\\\'));\n    $task = array_pop($parts);\n    $router->add($pattern, ['namespace' => implode('\\\\', $parts), 'task' => $task]);\n}","preventionTips":["Never put a leading backslash in task names used as route paths","Prefer separate 'namespace' and 'task' path keys over combined namespaced names","Validate dynamically built task names with a regex before add()"],"tags":["phalcon","cli","router","route","namespace"],"backgroundTag":"route-definition-invalid","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}