anomalyco/sst · error

failed to open source binary: %w

Error message

failed to open source binary: %w

What it means

Rust runtime Build opens the compiled binary (target/... binary located via the cargo metadata root) and wraps os.Open failures with this message. It means the Rust binary expected at `binary` could not be read — usually the cargo build didn't produce it where the runtime looked.

Source

Thrown at pkg/runtime/rust/rust.go:152

		name = parts[len(parts)-1]
	}
	binary := filepath.Join(root, "target",
		map[bool]string{
			true:  filepath.Join("debug", name),
			false: filepath.Join("lambda", name, "bootstrap"),
		}[input.Dev],
	)
	out := filepath.Join(input.Out(), "bootstrap")

	r.directories[input.FunctionID], _ = filepath.Abs(root)

	if err := os.MkdirAll(filepath.Dir(out), 0755); err != nil {
		return nil, fmt.Errorf("failed to create output directory: %w", err)
	}

	source, err := os.Open(binary)
	if err != nil {
		return nil, fmt.Errorf("failed to open source binary: %w", err)
	}
	defer source.Close()

	destination, err := os.Create(out)
	if err != nil {
		return nil, fmt.Errorf("failed to create destination file: %w", err)
	}
	defer destination.Close()

	if _, err := io.Copy(destination, source); err != nil {
		return nil, fmt.Errorf("failed to copy binary: %w", err)
	}

	if err := os.Chmod(out, 0755); err != nil {
		return nil, fmt.Errorf("failed to make binary executable: %w", err)
	}

	return &runtime.BuildOutput{

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Run `cargo build --release` manually in the project and confirm the binary exists at the path in the error
  2. Verify the target triple matches (use Cargo config [build].target or expected cross-compile flags)
  3. Clean stale target state (`cargo clean`) and redeploy so the binary is rebuilt
  4. Check the rust/ directory path in the SST config points at the crate containing the binary

Example fix

// before
cargo build --release // output at target/aarch64-unknown-linux-musl/release/, runtime expects target/release/
// after
cargo build --release --target x86_64-unknown-linux-musl // with matching expected target config
Defensive patterns

Strategy: validation

Validate before calling

# before deploy, confirm the binary exists where the runtime expects it
cargo build --release
ls target/release/<bin> || ls target/$CARGO_TARGET/release/<bin>

Try / catch

if err := sstDeploy(); err != nil {
	if strings.Contains(err.Error(), "failed to open source binary") {
		// run cargo build --release manually, check target triple, then redeploy
	}
}

Prevention

When it happens

Trigger: os.Open(binary) fails because the cargo build output is missing (build skipped/failed earlier but wasn't surfaced), the binary path was computed from the wrong target dir (cross-compile target triple mismatch), or the file was deleted by `cargo clean` between build and copy.

Common situations: Cross-compiling (e.g. x86_64-unknown-linux-musl) with the output under target/<triple>/release while the runtime looks in target/release/; cargo build failed or was interrupted; running on an architecture (Apple Silicon) where the default target differs from the expected one.

Related errors


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