xai-org/grok-build · error

{what} '{value}' contains whitespace or control characters

Error message

{what} '{value}' contains whitespace or control characters

What it means

ensure_ref_arg_safe rejects ref values containing whitespace or control characters because git refs cannot contain them, and embedded control characters (newlines, NULs, ANSI escapes) can corrupt CLI argument construction or log output. The library throws this to stop malformed client-influenced refs from reaching spawned git processes.

Source

Thrown at crates/codegen/xai-grok-workspace/src/session/git.rs:3089

            .map(str::to_owned)
            .collect();
        return Ok(GitSyncBaseResult {
            outcome: GitSyncBaseOutcome::Conflicts { files },
        });
    }
    anyhow::bail!("merge of base ref '{base}' failed: {merge_out}")
}
/// Reject a ref/branch value that could be parsed as a git option (leading `-`)
/// or that carries whitespace/control characters or `..`. A boundary guard for
/// client-influenced refs (notably `base_ref`) so they cannot be smuggled in as
/// flags; combined with `--end-of-options` at each call site.
fn ensure_ref_arg_safe(value: &str, what: &str) -> Result<()> {
    anyhow::ensure!(!value.is_empty(), "{what} must not be empty");
    anyhow::ensure!(
        !value.starts_with('-'),
        "{what} '{value}' must not start with '-'"
    );
    anyhow::ensure!(
        !value.chars().any(|c| c.is_whitespace() || c.is_control()),
        "{what} '{value}' contains whitespace or control characters"
    );
    anyhow::ensure!(
        !value.contains(".."),
        "{what} '{value}' must not contain '..'"
    );
    Ok(())
}
/// Seed a committed `.gitignore` (secrets never enter git)
/// when a fresh conversation branch is created and the repo has none. Distinct
/// from [`seed_default_excludes`], which seeds the *local-only* `info/exclude`
/// as a `stage_all` backstop; this file is meant to be committed, so it also
/// protects explicit user commits and BYO-remote exports. Never overwrites an
/// existing `.gitignore`.
async fn seed_default_gitignore(git_root: &Path) -> Result<()> {
    let path = git_root.join(".gitignore");
    if tokio::fs::metadata(&path).await.is_ok() {

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Trim the ref and remove/replace whitespace (use '-' or '_' as separators) before calling the API.
  2. Decode or re-parse the ref from a structured source (JSON field, not scraped text) so control characters are not carried over.
  3. Reject the input at your own boundary using value.chars().all(|c| !c.is_whitespace() && !c.is_control()).

Example fix

// before
let branch = format!("{}\n", stdout_line); // ref scraped from git output
// after
let branch = stdout_line.trim().to_string();
anyhow::ensure!(branch.chars().all(|c| !c.is_whitespace() && !c.is_control()), "invalid ref");
Defensive patterns

Strategy: validation

Validate before calling

let clean = ref_name.trim();
if clean.is_empty() || clean.chars().any(|c| c.is_whitespace() || c.is_control()) {
    return Err("ref contains whitespace or control characters".into());
}

Prevention

When it happens

Trigger: Passing a ref containing a space, tab, newline, or any char where c.is_whitespace() || c.is_control() into a git operation validated by ensure_ref_arg_safe (crates/codegen/xai-grok-workspace/src/session/git.rs:3089), e.g. branch = "feature x" or a ref parsed out of a log line including a trailing '\n'.

Common situations: A branch name with spaces created in another tool; a ref extracted from text output without trimming the trailing newline; copy-pasted branch names with non-breaking spaces; a payload with embedded '\n' attempting log/command injection.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/587801729520b3f5. Report an issue: GitHub.