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.

Solutions

  1. Clamp `uri` to the path's actual component count before calling `with`.
  2. Recompute the count from the exact same URL passed to `with`, not a stale one.
  3. Treat root (`/`) as not countable the same way as named components when deriving counts.
  4. 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

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


AI-assisted analysis of sxyazi/yazi@8ebf930f17 (2026-09-02). Data as JSON: /api/errors/b9b7b85dc44747cc. Report an issue: GitHub.

Appendix: 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
	where

View on GitHub (pinned to 8ebf930f17)