GitoxideLabs/gitoxide · error

cannot find character that we didn't search for

Error message

cannot find character that we didn't search for

What it means

An `unreachable!()` panic in `gix_quote::undo`, the public function that unquotes C-style/ANSI-C quoted strings. While stripping backslash escapes the code iterates over characters it previously searched for (quote or backslash); the panic fires if `undo` encounters a byte position whose character was not part of that search set, meaning the escape-scanning index and the character iteration got out of sync.

Solutions

  1. Upgrade gix-quote / gix to the latest version and retry
  2. Sanitize or pre-validate the quoted input: ensure escapes are well-formed pairs (`\\`, `\"`) before calling `undo`
  3. If the input comes from another tool, prefer obtaining the raw unquoted value from the source instead of undo-ing the quoted form
  4. Report the exact input bytes upstream as a gix-quote bug
Defensive patterns

Strategy: validation

Validate before calling

fn looks_like_ansi_c_quoted(s: &[u8]) -> bool {
    // well-formed: starts with '"', escapes are paired, ends with unescaped '"'
    s.starts_with(b"\"") && s.ends_with(b"\"") && (s.len() < 2 || s[s.len()-2] != b'\\')
}

Type guard

fn unquote_or_none(s: &[u8]) -> Option<std::borrow::Cow<'_, gix_hash::bstr::BStr>> {
    if looks_like_ansi_c_quoted(s) { gix_quote::undo(s).ok() } else { Some(std::borrow::Cow::Borrowed(s.as_bstr())) }
}

Try / catch

std::panic::catch_unwind(|| gix_quote::undo(quoted))
    .ok()
    .map(|r| r.ok())
    .unwrap_or_else(|| Some(std::borrow::Cow::Borrowed(quoted.as_bstr()))) // fallback: treat as unquoted

Prevention

When it happens

Trigger: Calling `gix_quote::undo` on a byte string containing ANSI-C quoted content (e.g. a path from `git config --get` output or `core.quotePath`-style output) whose escape sequence layout hits an out-of-sync branch — e.g. a string ending in a lone backslash or a misplaced escape immediately before the closing quote; effectively a bug in gix-quote's undo scanner.

Common situations: Consuming output produced by other tools (git CLI, third-party writers) that emit slightly non-standard quoting, or using a gix-quote version with an incomplete escape-handling fix; users on standard git-produced quoted paths don't hit it.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of GitoxideLabs/gitoxide@e73179060b (2026-09-08). Data as JSON: /api/errors/5f4985569dd88467. Report an issue: GitHub.

Appendix: source

Thrown at gix-quote/src/ansi_c.rs:132

                                    .read_exact(&mut buf[1..])
                                    .expect("impossible to fail as numbers match");
                                let byte = gix_utils::btoi::to_unsigned_with_radix(&buf, 8).or_raise(|| {
                                    ValidationError::new_with_input("Invalid octal escape value", original)
                                })?;
                                out.push(byte);
                                input = &input[2..];
                                consumed += 2;
                            }
                            _ => {
                                return Err(ValidationError::new_with_input(
                                    format!("Invalid escaped value {next}"),
                                    original,
                                )
                                .raise());
                            }
                        }
                    }
                    _ => unreachable!("cannot find character that we didn't search for"),
                }
            }
            None => {
                return Err(
                    ValidationError::new_with_input("Missing closing quote in quoted string", original).raise(),
                );
            }
        }
    }
    Ok((out.into(), consumed))
}

View on GitHub (pinned to e73179060b)