astral-sh/ruff · error

`uv sync` failed to run with exit code

Error message

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

What it means

The `ty_completion_bench` tool runs `uv sync` in the discovered project directory to provision the `.venv` used for completion benchmarking. If the subprocess exits with a non-zero status, the tool aborts with this error, embedding the exit code and the subprocess's stderr. It means the target project's environment could not be synced, not a bug in ty itself.

Solutions

  1. Run `uv sync` manually in the project directory and fix the underlying resolution or network error it reports
  2. Check the stderr portion of the message for the failing package or index and correct `pyproject.toml`/`uv.lock` accordingly
  3. Verify `uv` is installed and up to date (`uv self update` or reinstall)
  4. Regenerate the lockfile with `uv lock` if it is stale or conflicted
  5. If offline, ensure all dependencies are cached or use `--offline` with a warm cache

Example fix

// before
# pyproject.toml
[project]
dependencies = ["torch==99.0.0"]  # nonexistent version
// after
[project]
dependencies = ["torch>=2.0"]
# then: uv sync
Defensive patterns

Strategy: validation

Validate before calling

# before invoking the tool
uv sync --check || { uv sync; }  # ensure the project env resolves
# or in shell: test -x "$(command -v uv)" && uv lock --check

Try / catch

match ty_completion_bench::run(args) {
    Err(e) if e.to_string().contains("`uv sync` failed") => {
        eprintln!("fix project env: {e}");
        std::process::ExitCode::from(1)
    }
    other => other,
}

Prevention

When it happens

Trigger: Running `ty_completion_bench <file> <offset>` when `uv sync` in the file's containing project fails: invalid or unresolvable `pyproject.toml` dependencies, no network access to package indexes, a missing or broken `uv` installation, lockfile conflicts, or Python interpreter discovery failures.

Common situations: Benchmarking in a project with an unpinned private dependency that is unreachable offline; a stale or corrupted `uv.lock`; running inside a sandbox without internet; `VIRTUAL_ENV` pointing somewhere unusual while the project requires a fresh sync; typo'd requirement specifiers in `pyproject.toml`.

Related errors


AI-assisted analysis of astral-sh/ruff@5bb508f594 (2026-09-05). Data as JSON: /api/errors/a85156203ebab674. Report an issue: GitHub.

Appendix: 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.set_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 5bb508f594)