{"record":{"id":"a85156203ebab674","repo":"astral-sh/ruff","slug":"uv-sync-failed-to-run-with-exit-code-code-s","errorCode":null,"errorMessage":"`uv sync` failed to run with exit code `{code}`, stderr: {stderr}","messagePattern":"`uv sync` failed to run with exit code `(.+?)`, stderr: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ty_completion_bench/src/main.rs","lineNumber":88,"sourceCode":"        format!(\n            \"failed to convert file offset `{}` to 32-bit integer\",\n            args.offset\n        )\n    })?;\n\n    let uv_sync_output = std::process::Command::new(\"uv\")\n        .arg(\"sync\")\n        .current_dir(&project_dir)\n        .output()\n        .with_context(|| format!(\"failed to run `uv sync` in `{project_dir}`\"))?;\n    if !uv_sync_output.status.success() {\n        let code = uv_sync_output\n            .status\n            .code()\n            .map(|code| code.to_string())\n            .unwrap_or_else(|| \"UNKNOWN\".to_string());\n        let stderr = bstr::BStr::new(&uv_sync_output.stderr);\n        anyhow::bail!(\"`uv sync` failed to run with exit code `{code}`, stderr: {stderr}\")\n    }\n\n    let system = OsSystem::new(&project_dir);\n    let mut project_metadata = ProjectMetadata::discover(&project_dir, &system)?;\n    // Explicitly point ty to the .venv to avoid any set VIRTUAL_ENV variable to take precedence.\n    project_metadata.set_override_options(Options {\n        environment: Some(EnvironmentOptions {\n            python: Some(RelativePathBuf::cli(\".venv\")),\n            ..EnvironmentOptions::default()\n        }),\n        ..Options::default()\n    });\n    let db = ProjectDatabase::fallible(project_metadata, system)?;\n\n    let start = std::time::Instant::now();\n    let mut completions = get_completions(&db, &args.file, offset)?;\n    let elapsed = std::time::Instant::now().duration_since(start);\n    eprintln!(\"total elapsed for initial completions request: {elapsed:?}\");","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/astral-sh/ruff/blob/5bb508f59481c1a02d5c7ff8568b9ffd8a763eef/crates/ty_completion_bench/src/main.rs#L70-L106","documentation":"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.","triggerScenarios":"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.","commonSituations":"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`.","solutions":["Run `uv sync` manually in the project directory and fix the underlying resolution or network error it reports","Check the stderr portion of the message for the failing package or index and correct `pyproject.toml`/`uv.lock` accordingly","Verify `uv` is installed and up to date (`uv self update` or reinstall)","Regenerate the lockfile with `uv lock` if it is stale or conflicted","If offline, ensure all dependencies are cached or use `--offline` with a warm cache"],"exampleFix":"// before\n# pyproject.toml\n[project]\ndependencies = [\"torch==99.0.0\"]  # nonexistent version\n// after\n[project]\ndependencies = [\"torch>=2.0\"]\n# then: uv sync","handlingStrategy":"validation","validationCode":"# before invoking the tool\nuv sync --check || { uv sync; }  # ensure the project env resolves\n# or in shell: test -x \"$(command -v uv)\" && uv lock --check","typeGuard":null,"tryCatchPattern":"match ty_completion_bench::run(args) {\n    Err(e) if e.to_string().contains(\"`uv sync` failed\") => {\n        eprintln!(\"fix project env: {e}\");\n        std::process::ExitCode::from(1)\n    }\n    other => other,\n}","preventionTips":["Commit a valid uv.lock and keep dependencies resolvable","Run `uv sync` once before benchmarking so failures surface early","Check network/proxy access to your package index before running offline-sensitive tools"],"tags":["subprocess","uv","environment-setup","cli"],"backgroundTag":"uv-sync-failed","analyzedSha":"5bb508f59481c1a02d5c7ff8568b9ffd8a763eef","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}