gitui-org/gitui · critical

invalid path.

Error message

invalid path.

What it means

While rendering the status tree, gitui takes each changed file's path and extracts its final component via Path::file_name(), then converts it with OsStr::to_str(). file_name() returns None for degenerate paths that end in a parent component (e.g. '..' or a root), and to_str() returns None when the bytes are not valid UTF-8; either case trips this expect() and panics the render path, crashing the UI.

Source

Thrown at src/components/status_tree.rs:178

	) -> Option<Span<'b>> {
		let indent_str = if indent == 0 {
			String::new()
		} else {
			format!("{:w$}", " ", w = indent * 2)
		};

		if !visible {
			return None;
		}

		match file_item_kind {
			FileTreeItemKind::File(status_item) => {
				let status_char =
					Self::item_status_char(status_item.status);
				let file = Path::new(&status_item.path)
					.file_name()
					.and_then(std::ffi::OsStr::to_str)
					.expect("invalid path.");

				let txt = if selected {
					format!(
						"{} {}{:w$}",
						status_char,
						indent_str,
						file,
						w = width as usize
					)
				} else {
					format!("{status_char} {indent_str}{file}")
				};

				Some(Span::styled(
					Cow::from(txt),
					theme.item(status_item.status, selected),
				))
			}

View on GitHub (pinned to 2fa693cb6e)

Solutions

  1. Find the offender: git -c core.quotepath=false status --porcelain | LC_ALL=C grep -n '[^ -~]' to spot non-ASCII/broken names.
  2. Rename the offending file to valid UTF-8 (git mv for tracked files) or remove it from the working tree.
  3. Update gitui - path handling in the status tree was hardened in later releases; report the panic trace with the path bytes if it reproduces on a current build.

Example fix

// before
let file = Path::new(&status_item.path)
    .file_name()
    .and_then(std::ffi::OsStr::to_str)
    .expect("invalid path.");
// after: degrade instead of panicking
let file = Path::new(&status_item.path)
    .file_name()
    .and_then(std::ffi::OsStr::to_str)
    .unwrap_or("(invalid path)");
Defensive patterns

Strategy: validation

Validate before calling

# repo hygiene check before opening the status view
git -c core.quotepath=false status --porcelain | LC_ALL=C grep -n '[^ -~]'
# any output line is a candidate crash trigger

// Rust: pre-check each path before rendering
Path::new(&p).file_name().and_then(std::ffi::OsStr::to_str).is_some()

Prevention

When it happens

Trigger: A filename in the git status output containing non-UTF-8 bytes (media files with legacy latin-1/Shift-JIS names, archives extracted on other systems); a degenerate path ending in '..' produced by renames or tooling.

Common situations: Repos with legacy encoded filenames; files created by Windows/macOS tools with unusual encodings; untracked files with byte sequences invalid in UTF-8 appearing in the status view.

Related errors


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