actix/actix-web · error
Value for parameter is not available
Error message
Value for parameter is not available
What it means
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.
Source
Thrown at actix-router/src/path.rs:262
let res = match self.params.segments[idx].1 {
PathItem::Static(ref seg) => seg,
PathItem::Segment(start, end) => {
&self.params.path.path()[(start as usize)..(end as usize)]
}
};
self.idx += 1;
return Some((&self.params.segments[idx].0, res));
}
None
}
}
impl<'a, T: ResourcePath> Index<&'a str> for Path<T> {
type Output = str;
fn index(&self, name: &'a str) -> &str {
self.get(name)
.expect("Value for parameter is not available")
}
}
impl<T: ResourcePath> Index<usize> for Path<T> {
type Output = str;
fn index(&self, idx: usize) -> &str {
match self.segments[idx].1 {
PathItem::Static(ref seg) => seg,
PathItem::Segment(start, end) => &self.path.path()[(start as usize)..(end as usize)],
}
}
}
impl<T: ResourcePath> Resource for Path<T> {
type Path = T;
fn resource_path(&mut self) -> &mut Path<Self::Path> {View on GitHub (pinned to 7ae209e4a4)
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>) -> ...`
Example fix
// before
#[get("/users/{id}")]
async fn handler(req: HttpRequest) -> String {
req.match_info()["name"].to_string() // panics: "name" not in route
}
// after
#[get("/users/{id}")]
async fn handler(req: HttpRequest) -> String {
req.match_info().get("id").unwrap_or_default().to_string()
} Defensive patterns
Strategy: validation
Validate before calling
// Check parameter existence before indexing.
fn get_param(req: &actix_web::HttpRequest, name: &str) -> Option<&str> {
req.match_info().get(name)
}
// Usage:
if let Some(id) = get_param(&req, "id") {
// use id
} else {
// handle missing parameter
} Type guard
fn has_path_param(req: &actix_web::HttpRequest, name: &str) -> bool {
req.match_info().get(name).is_some()
} Try / catch
// Avoid indexing; use .get() which returns Option.
// If you must handle it safely:
let id = req.match_info().get("id").unwrap_or_else(|| {
panic!("expected 'id' parameter in route");
});
// Better: use the Path extractor for type-safe access
// async fn handler(Path(id): Path<String>) -> impl Responder { ... } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- invalid service definition, expected #[<method>("<path>")]
- Multiple paths specified! There should be only one.
- The #[route(..)] macro requires at least one `method` attrib
- The #[routes] macro requires at least one `#[<method>(..)]`
- missing arguments for scope macro, expected: #[scope("/prefi
AI-assisted analysis of actix/actix-web@7ae209e4a4 (2026-08-09).
Data as JSON: /api/errors/76b23694f576e7d6.
Report an issue: GitHub.