seanmonstar/warp · info

split always has at least 1

Error message

split always has at least 1

What it means

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.

Solutions

  1. No action needed — this is an internal invariant that cannot fire from the public API
  2. If you are vendoring/modifying warp, preserve the guarantee that `route.path()` is always a valid &str before calling segment
Defensive patterns

Strategy: try-catch

Prevention

When it happens

Trigger: 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.

Common situations: Only conceivable if the internal route/path bookkeeping changed across warp versions; users never see it in normal operation.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of seanmonstar/warp@ff34d7213e (2026-09-09). Data as JSON: /api/errors/df4c47233784458d. Report an issue: GitHub.

Appendix: source

Thrown at src/filters/path.rs:461

fn with_segment<F, U>(route: &mut Route, func: F) -> Result<U, Rejection>
where
    F: Fn(&str) -> Result<U, Rejection>,
{
    let seg = segment(route);
    let ret = func(seg);
    if ret.is_ok() {
        let idx = seg.len();
        route.set_unmatched_path(idx);
    }
    ret
}

fn segment(route: &Route) -> &str {
    route
        .path()
        .splitn(2, '/')
        .next()
        .expect("split always has at least 1")
}

fn path_and_query(route: &Route) -> PathAndQuery {
    route
        .uri()
        .path_and_query()
        .cloned()
        .unwrap_or_else(|| PathAndQuery::from_static("/"))
}

/// Convenient way to chain multiple path filters together.
///
/// Any number of either type identifiers or string expressions can be passed,
/// each separated by a forward slash (`/`). Strings will be used to match
/// path segments exactly, and type identifiers are used just like
/// [`param`](crate::path::param) filters.
///
/// # Example

View on GitHub (pinned to ff34d7213e)