anomalyco/sst · error

failed to create output directory: %w

Error message

failed to create output directory: %w

What it means

Rust runtime Build creates the output directory (the parent of <bundle>/bootstrap) via os.MkdirAll and wraps failures with this message. It fails when the directory cannot be created — missing ancestor that can't be created, permission denied, or the path exists as a non-directory. The rust build then copies the compiled binary into this location.

Source

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

	}

	// if binary name is not specified, use the package name
	name := cargotoml.Package.Name
	if len(parts) >= 2 {
		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)
	}

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Check permissions/ownership of the .sst output directory and create it writable (chown/chmod)
  2. Remove any file conflicting with the expected output directory path
  3. Run the deploy as a user with write access to the project root
  4. Inspect the wrapped os error text for the precise cause (permission denied vs not a directory)

Example fix

// before
sst deploy run as root, output owned by non-root
// after
sudo chown -R $(whoami) .sst && bun run build:cli && sst deploy
Defensive patterns

Strategy: validation

Validate before calling

const out = path.join(projectRoot, ".sst", "dist")
fs.mkdirSync(out, { recursive: true })
fs.accessSync(out, fs.constants.W_OK) // throws early if not writable

Try / catch

if err := sstDeploy(); err != nil {
	if strings.Contains(err.Error(), "failed to create output directory") {
		// chown/chmod the .sst output dir or clear a conflicting file, then retry
	}
}

Prevention

When it happens

Trigger: os.MkdirAll(filepath.Dir(out), 0755) errors: output root (.sst output path) is read-only or owned by another user, a file exists where a directory is expected, or the path is too long/invalid.

Common situations: Running deploy as non-root inside a container whose output volume is root-owned; a corrupted .sst directory containing a file named like the expected function output dir; restricted sandbox (CI runner) denying writes to the project directory.

Related errors


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