sxyazi/yazi · critical
URI exceeds the entire URL
Error message
URI exceeds the entire URL
What it means
`Loc::with` walks the path's components backwards `uri` times to compute the URI prefix boundary. If the URL has fewer components than the requested `uri` count, the iterator is exhausted and it bails with "URI exceeds the entire URL". The URI count must not exceed the actual number of components in the path.
Source
Thrown at yazi-shared/src/loc/loc.rs:225
where
T: PathView<'p, P>,
{
if urn > uri {
bail!("URN cannot be longer than URI");
}
let mut loc = Self::bare(path);
if uri == 0 {
(loc.uri, loc.urn) = (0, 0);
return Ok(loc);
} else if urn == 0 {
loc.urn = 0;
}
let mut it = loc.inner.components();
for i in 1..=uri {
if it.next_back().is_none() {
bail!("URI exceeds the entire URL");
}
if i == urn {
loc.urn = loc.strip_prefix(it.clone()).unwrap().len();
}
if i == uri {
loc.uri = loc.strip_prefix(it).unwrap().len();
break;
}
}
if loc.urn().has_root() {
bail!("URN cannot include a root directory");
}
Ok(loc)
}
pub(crate) fn zeroed<T>(path: T) -> Self
whereView on GitHub (pinned to 8ebf930f17)
Solutions
- Clamp `uri` to the path's actual component count before calling `with`.
- Recompute the count from the exact same URL passed to `with`, not a stale one.
- Treat root (`/`) as not countable the same way as named components when deriving counts.
- On version upgrades, re-derive Loc state instead of reusing cached (uri, urn) counters across URLs.
Example fix
// before let loc = Loc::with(shortened_url, old_count, urn_count)?; // old_count from a deeper path // after let count = old_count.min(shortened_url.components().count()); let loc = Loc::with(shortened_url, count, urn_count.min(count))?;
Defensive patterns
Strategy: validation
Validate before calling
fn clamp_uri(url: &Url, uri: usize) -> usize {
uri.min(url.components().count())
} Try / catch
let count = stale_count.min(url.components().count()); let loc = Loc::with(url, count, urn_count.min(count))?;
Prevention
- Never reuse (uri, urn) counts across different URLs; recompute per path.
- Clamp counts to the path's component count before calling with().
- Recalculate Loc state after tab/preview URL changes.
- Remember the root component is not a normal component when counting.
When it happens
Trigger: Calling `Loc::with(path, uri, urn)` where `uri` is larger than the number of components in `path.inner` — e.g. `with("/a/b.txt", 5, 1)` on a path with only two components; counts computed from a different (deeper) path then applied to a shallower one.
Common situations: Hover/parent logic that carries a component count from a child URL to a shortened parent URL; cache-keyed Loc state reused across URL changes in a preview or tab switch; off-by-one counting that includes the root as a component.
Related errors
- URN cannot be longer than URI
- URN cannot include a root directory
- not a URL
- not a number
- argument not found: {:?}
AI-assisted analysis of sxyazi/yazi@8ebf930f17 (2026-09-02).
Data as JSON: /api/errors/b9b7b85dc44747cc.
Report an issue: GitHub.