sxyazi/yazi · error

failed to parse chafa output

Error message

failed to parse chafa output

What it means

The first line of chafa's stdout could not be decoded as text (invalid UTF-8) or contained no lines after splitting, so the parser cannot extract the pixel dimensions it needs. The guard sits right after splitting stdout into lines and calling `to_text()`; the faulting input is chafa's raw output itself.

Source

Thrown at yazi-adapter/src/drivers/chafa.rs:51

			.arg(format!("{}x{}", max.width, max.height))
			.arg(path)
			.stdin(Stdio::null())
			.stdout(Stdio::piped())
			.stderr(Stdio::null())
			.kill_on_drop(true)
			.spawn()
			.map_err(|e| anyhow!("failed to spawn chafa: {e}"))?;

		let output = child.wait_with_output().await?;
		if !output.status.success() {
			bail!("chafa failed with status: {}", output.status);
		} else if output.stdout.is_empty() {
			bail!("chafa returned no output");
		}

		let lines: Vec<_> = output.stdout.split(|&b| b == b'\n').collect();
		let Ok(Some(first)) = lines[0].to_text().map(|mut t| t.lines.pop()) else {
			bail!("failed to parse chafa output");
		};

		let area = Rect {
			x:      max.x,
			y:      max.y,
			width:  first.width() as u16,
			height: lines.len() as u16,
		};

		ADAPTOR.image_hide()?;
		ADAPTOR.shown_store(area);
		Emulator::move_lock((max.x, max.y), |w| {
			for (i, line) in lines.into_iter().enumerate() {
				w.write_all(line)?;
				write!(w, "{}", MoveTo(max.x, max.y + i as u16 + 1))?;
			}
			Ok(area)
		})

View on GitHub (pinned to 5f901b886b)

Solutions

  1. Check the chafa version in use — output format may differ from what the parser expects.
  2. Reproduce the chafa invocation manually and inspect stdout for binary or unexpected content.
  3. Handle a decode failure by skipping the preview instead of aborting the task.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at yazi-adapter/src/drivers/chafa.rs:51 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of sxyazi/yazi@5f901b886b (2026-09-02). Data as JSON: /api/errors/61cf337532e262ac. Report an issue: GitHub.