{"record":{"id":"76b23694f576e7d6","repo":"actix/actix-web","slug":"value-for-parameter-is-not-available","errorCode":null,"errorMessage":"Value for parameter is not available","messagePattern":"Value for parameter is not available","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"actix-router/src/path.rs","lineNumber":262,"sourceCode":"            let res = match self.params.segments[idx].1 {\n                PathItem::Static(ref seg) => seg,\n                PathItem::Segment(start, end) => {\n                    &self.params.path.path()[(start as usize)..(end as usize)]\n                }\n            };\n            self.idx += 1;\n            return Some((&self.params.segments[idx].0, res));\n        }\n        None\n    }\n}\n\nimpl<'a, T: ResourcePath> Index<&'a str> for Path<T> {\n    type Output = str;\n\n    fn index(&self, name: &'a str) -> &str {\n        self.get(name)\n            .expect(\"Value for parameter is not available\")\n    }\n}\n\nimpl<T: ResourcePath> Index<usize> for Path<T> {\n    type Output = str;\n\n    fn index(&self, idx: usize) -> &str {\n        match self.segments[idx].1 {\n            PathItem::Static(ref seg) => seg,\n            PathItem::Segment(start, end) => &self.path.path()[(start as usize)..(end as usize)],\n        }\n    }\n}\n\nimpl<T: ResourcePath> Resource for Path<T> {\n    type Path = T;\n\n    fn resource_path(&mut self) -> &mut Path<Self::Path> {","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/actix/actix-web/blob/7ae209e4a4f3c8df61cacb9c2d3b8ef28ebda0d6/actix-router/src/path.rs#L244-L280","documentation":"This is a runtime panic from the `Index<&str>` implementation on `Path<T>`. When you access a path parameter by name using `req.match_info()[\"param_name\"]` and that parameter does not exist in the matched route's segments, `.get(name)` returns `None` and `.expect(\"Value for parameter is not available\")` at line 262 panics.","triggerScenarios":"Indexing into `match_info()` with a parameter name that was not declared in the route pattern. For example, registering `#[get(\"/users/{id}\")]` but accessing `match_info()[\"name\"]` (which doesn't exist in the route). Also happens if the route pattern has no dynamic segments at all.","commonSituations":"Mismatch between route parameter names and handler access, refactoring routes without updating handlers, or typos in parameter names. Also occurs when trying to access parameters from a sub-request or a route that didn't match the expected pattern.","solutions":["Use the safe `.get()` method instead of indexing: `req.match_info().get(\"id\").unwrap_or(\"\")`","Ensure the parameter name in the route pattern matches what the handler accesses: `/users/{id}` requires `match_info()[\"id\"]`","Use `Path` extractor with serde for type-safe parameter extraction: `async fn handler(Path(id): Path<String>) -> ...`"],"exampleFix":"// before\n#[get(\"/users/{id}\")]\nasync fn handler(req: HttpRequest) -> String {\n    req.match_info()[\"name\"].to_string() // panics: \"name\" not in route\n}\n\n// after\n#[get(\"/users/{id}\")]\nasync fn handler(req: HttpRequest) -> String {\n    req.match_info().get(\"id\").unwrap_or_default().to_string()\n}","handlingStrategy":"validation","validationCode":"// Check parameter existence before indexing.\nfn get_param(req: &actix_web::HttpRequest, name: &str) -> Option<&str> {\n    req.match_info().get(name)\n}\n\n// Usage:\nif let Some(id) = get_param(&req, \"id\") {\n    // use id\n} else {\n    // handle missing parameter\n}","typeGuard":"fn has_path_param(req: &actix_web::HttpRequest, name: &str) -> bool {\n    req.match_info().get(name).is_some()\n}","tryCatchPattern":"// Avoid indexing; use .get() which returns Option.\n// If you must handle it safely:\nlet id = req.match_info().get(\"id\").unwrap_or_else(|| {\n    panic!(\"expected 'id' parameter in route\");\n});\n// Better: use the Path extractor for type-safe access\n// async fn handler(Path(id): Path<String>) -> impl Responder { ... }","preventionTips":["Never use req.match_info()[\"name\"] indexing; use .get(\"name\") which returns Option","Prefer the Path<T> extractor for type-safe, panic-free parameter access","Keep route parameter names and handler access in sync; use consistent naming","Add integration tests that verify all route parameters are accessible in handlers"],"tags":["rust","actix-web","routing","runtime-panic","path-params"],"backgroundTag":null,"analyzedSha":"7ae209e4a4f3c8df61cacb9c2d3b8ef28ebda0d6","analyzedAt":"2026-08-09T01:01:40.926Z","contentChangedAt":"2026-08-09T01:01:40.926Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}