astral-sh/ruff · error · anyhow::Error

`uv sync` failed to run with exit code `{code}`, stderr: {st

Error message

`uv sync` failed to run with exit code `{code}`, stderr: {stderr}

What it means

The `ty_completion_bench` harness prepares each benchmark project by running `uv sync` inside it (creating/refreshing its `.venv`) before constructing the `ProjectDatabase`. This error means uv itself executed but exited non-zero; the exit code (or `UNKNOWN` if terminated by signal) and uv's raw stderr are embedded in the message so the underlying failure is visible.

Source

Thrown at crates/ty_completion_bench/src/main.rs:88

        format!(
            "failed to convert file offset `{}` to 32-bit integer",
            args.offset
        )
    })?;

    let uv_sync_output = std::process::Command::new("uv")
        .arg("sync")
        .current_dir(&project_dir)
        .output()
        .with_context(|| format!("failed to run `uv sync` in `{project_dir}`"))?;
    if !uv_sync_output.status.success() {
        let code = uv_sync_output
            .status
            .code()
            .map(|code| code.to_string())
            .unwrap_or_else(|| "UNKNOWN".to_string());
        let stderr = bstr::BStr::new(&uv_sync_output.stderr);
        anyhow::bail!("`uv sync` failed to run with exit code `{code}`, stderr: {stderr}")
    }

    let system = OsSystem::new(&project_dir);
    let mut project_metadata = ProjectMetadata::discover(&project_dir, &system)?;
    // Explicitly point ty to the .venv to avoid any set VIRTUAL_ENV variable to take precedence.
    project_metadata.apply_override_options(Options {
        environment: Some(EnvironmentOptions {
            python: Some(RelativePathBuf::cli(".venv")),
            ..EnvironmentOptions::default()
        }),
        ..Options::default()
    });
    let db = ProjectDatabase::fallible(project_metadata, system)?;

    let start = std::time::Instant::now();
    let mut completions = get_completions(&db, &args.file, offset)?;
    let elapsed = std::time::Instant::now().duration_since(start);
    eprintln!("total elapsed for initial completions request: {elapsed:?}");

View on GitHub (pinned to 672bb4edf0)

Solutions

  1. Reproduce manually: `cd <project-dir-from-error> && uv sync` and read the full uv output
  2. Install the required interpreter (`uv python install <version>`) or update uv (`uv self update`) and retry
  3. Refresh the lockfile (`uv lock`) after dependency edits, then re-run the bench
  4. Check network/proxy settings (UV_HTTP_TIMEOUT, HTTPS_PROXY) if downloads are failing

Example fix

# before: bench aborts with `uv sync` failed ...
cargo run -p ty_completion_bench -- ...
# after: fix the environment first, then bench
cd <fixture-project-dir> && uv sync && cd - && cargo run -p ty_completion_bench -- ...
Defensive patterns

Strategy: retry

Validate before calling

cd "$PROJECT_DIR" && uv sync --dry-run >/dev/null 2>&1 \
  || echo "warning: uv sync is not currently clean; bench may fail" >&2

Try / catch

# shell: bounded retry for transient uv failures (network flakes)
for i in 1 2; do
  (cd "$PROJECT_DIR" && uv sync) && break || { [ "$i" = 2 ] && exit 1; sleep 5; }
done

Prevention

When it happens

Trigger: Offline or proxied network blocking package downloads; a `uv.lock` stale relative to `pyproject.toml`; the fixture's pinned Python version not installed; a corrupted or permission-locked `.venv` inside the benchmark project directory.

Common situations: Running benchmarks on machines without network access; after editing fixture dependencies without relocking; after a toolchain upgrade removed the pinned interpreter; corporate proxies rejecting PyPI.

Related errors


AI-assisted analysis of astral-sh/ruff@672bb4edf0 (2026-08-16). Data as JSON: /api/errors/a85156203ebab674. Report an issue: GitHub.