gitui-org/gitui · critical

invalid path

Error message

invalid path

What it means

Building the collapsed/expanded file tree inserts directory ancestors for every changed path. Path::to_str() returns None when the path is not valid UTF-8, and the expect() (which carries a TODO to remove it) turns that into a panic while constructing the tree - the file/status view cannot render. Same input class as the status-tree panic, hit through the tree builder.

Source

Thrown at src/components/utils/filetree.rs:213

		parent_index
	}

	fn push_dirs<'a>(
		item_path: &'a Path,
		nodes: &mut Vec<FileTreeItem>,
		paths_added: &mut BTreeSet<&'a Path>,
		collapsed: &BTreeSet<&String>,
	) -> Result<()> {
		let mut ancestors =
			{ item_path.ancestors().skip(1).collect::<Vec<_>>() };
		ancestors.reverse();

		for c in &ancestors {
			if c.parent().is_some() && !paths_added.contains(c) {
				paths_added.insert(c);
				//TODO: get rid of expect
				let path_string =
					String::from(c.to_str().expect("invalid path"));
				let is_collapsed = collapsed.contains(&path_string);
				nodes.push(FileTreeItem::new_path(
					c,
					path_string,
					is_collapsed,
				)?);
			}
		}

		Ok(())
	}

	pub fn multiple_items_at_path(&self, index: usize) -> bool {
		let tree_items = self.items();
		let mut idx_temp_inner;
		if index + 2 < tree_items.len() {
			idx_temp_inner = index + 1;
			while idx_temp_inner < tree_items.len().saturating_sub(1)

View on GitHub (pinned to 2fa693cb6e)

Solutions

  1. Detect and rename offending paths: git -c core.quotepath=false ls-files | LC_ALL=C grep -n '[^ -~]', plus untracked files via git status --porcelain -uall.
  2. git mv the tracked offenders to UTF-8 names and delete/rename untracked ones.
  3. Update gitui - this expect is a known TODO that was reworked; report with the path bytes if it still reproduces.

Example fix

// before
let path_string = String::from(c.to_str().expect("invalid path"));
// after: skip or placeholder non-UTF-8 entries
let path_string = c.to_str().unwrap_or("(non-utf8 path)").to_string();
Defensive patterns

Strategy: validation

Validate before calling

# detect non-UTF-8 paths before launching into the tree view
git -c core.quotepath=false ls-files | LC_ALL=C grep -n '[^ -~]'
git -c core.quotepath=false status --porcelain --untracked-files=all | LC_ALL=C grep -n '[^ -~]'

Prevention

When it happens

Trigger: Any changed or untracked path whose bytes are invalid UTF-8, including parent directory names since ancestors are walked and inserted as nodes.

Common situations: Repos containing latin-1 or Shift-JIS named directories; files extracted from archives with mangled names; cross-platform checkouts that materialized unusual paths.

Related errors


AI-assisted analysis of gitui-org/gitui@2fa693cb6e (2026-08-16). Data as JSON: /api/errors/797daf9c1447bec0. Report an issue: GitHub.