{"record":{"id":"df4c47233784458d","repo":"seanmonstar/warp","slug":"split-always-has-at-least-1","errorCode":null,"errorMessage":"split always has at least 1","messagePattern":"split always has at least 1","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/filters/path.rs","lineNumber":461,"sourceCode":"fn with_segment<F, U>(route: &mut Route, func: F) -> Result<U, Rejection>\nwhere\n    F: Fn(&str) -> Result<U, Rejection>,\n{\n    let seg = segment(route);\n    let ret = func(seg);\n    if ret.is_ok() {\n        let idx = seg.len();\n        route.set_unmatched_path(idx);\n    }\n    ret\n}\n\nfn segment(route: &Route) -> &str {\n    route\n        .path()\n        .splitn(2, '/')\n        .next()\n        .expect(\"split always has at least 1\")\n}\n\nfn path_and_query(route: &Route) -> PathAndQuery {\n    route\n        .uri()\n        .path_and_query()\n        .cloned()\n        .unwrap_or_else(|| PathAndQuery::from_static(\"/\"))\n}\n\n/// Convenient way to chain multiple path filters together.\n///\n/// Any number of either type identifiers or string expressions can be passed,\n/// each separated by a forward slash (`/`). Strings will be used to match\n/// path segments exactly, and type identifiers are used just like\n/// [`param`](crate::path::param) filters.\n///\n/// # Example","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/seanmonstar/warp/blob/ff34d7213ed55ec342304aa7ff6ac4b351da9e66/src/filters/path.rs#L443-L479","documentation":"The internal `segment()` helper splits a route's remaining path on '/' with `splitn(2, '/')` and calls `.next().expect(\"split always has at least 1\")` (src/filters/path.rs:461). Since `splitn` always yields at least one element even for empty input, this expect is a pure internal invariant guard and effectively cannot fire. It documents warp's assumption about route path state during path-segment matching.","triggerScenarios":"Not triggerable from user code; the panic is a safety net inside `warp::path::segment` used by `path::param`/`with_segment`-style filters during route advancement.","commonSituations":"Only conceivable if the internal route/path bookkeeping changed across warp versions; users never see it in normal operation.","solutions":["No action needed — this is an internal invariant that cannot fire from the public API","If you are vendoring/modifying warp, preserve the guarantee that `route.path()` is always a valid &str before calling segment"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["No user-side action required; this is an internal invariant that cannot fire from the public API"],"tags":["internal-invariant","panic","routing"],"backgroundTag":"internal-invariant-violation","analyzedSha":"ff34d7213ed55ec342304aa7ff6ac4b351da9e66","analyzedAt":"2026-09-09T16:57:46.316Z","contentChangedAt":"2026-09-09T16:57:46.316Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}