anomalyco/sst · error

uv build failed (exit code %d): %s

Error message

uv build failed (exit code %d): %s

What it means

runUvBuild ran `uv build` successfully as a process but it exited with a non-zero code. The error embeds the exit code and uv's stderr, which normally contains the real reason (invalid pyproject.toml, missing build backend, compile error in the package, locked dependency conflicts). This is the structured-failure path as opposed to the process-spawn failure (uv build failed: %w).

Source

Thrown at pkg/runtime/python/build.go:1484

	args = append(args, "--no-sources")

	workingDir := cmd.PackageDir
	if workingDir == "" {
		workingDir = "."
	}

	result, err := runUvCommand(ctx, "uv", args, workingDir)
	if err != nil {
		slog.Error("UV build command failed",
			"package", cmd.PackageName,
			"command", "uv "+strings.Join(args, " "),
			"error", err)
		return fmt.Errorf("uv build failed: %w", err)
	}

	if !result.Success {
		return fmt.Errorf("uv build failed (exit code %d): %s", result.ExitCode, result.Stderr)
	}

	return nil
}

// runUvExport executes a UV export command
func runUvExport(ctx context.Context, cmd *uvExportCommand) error {
	args := []string{"export"}

	if cmd.AllPackages {
		args = append(args, "--all-packages")
	} else if cmd.PackageName != "" {
		args = append(args, "--package="+cmd.PackageName)
	}

	if cmd.OutputFile != "" {
		args = append(args, "--output-file="+cmd.OutputFile)
	}

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Read the %s stderr portion of the error — it contains uv's actual complaint; fix that first
  2. Ensure pyproject.toml has a valid [build-system] with an installable backend and correct project name/version
  3. Run `uv build` manually in the package directory to iterate quickly on the failure
  4. If the backend or toolchain is missing (gcc/rust for native deps), install it or pin a pure-Python build backend
  5. Check requires-python matches the Python version available to uv

Example fix

# before: uv build failed (exit code 1): error: Distribution ... does not have a `name`
# after (pyproject.toml)
[project]
name = "my-package"
version = "0.1.0"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
Defensive patterns

Strategy: try-catch

Validate before calling

# validate the package before invoking the build
uv build --help >/dev/null && cd packages/mypkg && uv build  # reproduce locally first
# check pyproject.toml essentials
python -c "import tomllib; c=tomllib.load(open('pyproject.toml','rb')); assert c['project']['name']; assert c['build-system']['build-backend']"

Try / catch

if err := buildPackage(ctx, cmd); err != nil {
    var exitErr *exec.ExitError
    // or parse the "uv build failed (exit code N)" wrapper
    if strings.Contains(err.Error(), "uv build failed (exit code") {
        slog.Error("uv build rejected the package", "stderr", err) // stderr carries root cause
    }
    return err
}

Prevention

When it happens

Trigger: buildPackage calls runUvBuild for a workspace package; uv runs but exits non-zero because the package's pyproject.toml is invalid, the declared build backend (setuptools/hatchling/maturin) is missing or fails, source files have syntax/import errors, or the build environment cannot resolve build requirements.

Common situations: Missing [build-system] table in pyproject.toml; hatchling/setuptools not resolvable in a pinned/offline CI environment; package name/version fields missing or malformed; native extension build toolchain (gcc, rust) absent; Python version mismatch declared via requires-python.

Related errors


AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30). Data as JSON: /api/errors/d8c0db51da3765d7. Report an issue: GitHub.