BoundaryML/baml · error
failed create destination %s: %w
Error message
failed create destination %s: %w
What it means
copyFile failed to create the destination file at dst via os.Create. This indicates the destination path is unwritable, its parent directory doesn't exist, or a permission/OS-level error; the error is embedded into ErrDownloadFailed by the caller.
Source
Thrown at engine/language_client_go/baml_go/lib_common.go:644
for _, r := range s {
if !((r >= '0' && r <= '9') || (r >= 'a' && r <= 'f') || (r >= 'A' && r <= 'F')) {
return false
}
}
return true
}
func copyFile(src, dst string) (err error) {
logger.Debug("Attempting to copy file", "source", src, "destination", dst)
source, err := os.Open(src)
if err != nil {
return fmt.Errorf("failed open source %s: %w", src, err)
}
defer source.Close()
destination, err := os.Create(dst)
if err != nil {
return fmt.Errorf("failed create destination %s: %w", dst, err)
}
defer func() {
cerr := destination.Close()
if err == nil && cerr != nil {
err = fmt.Errorf("failed close destination %s: %w", dst, cerr)
}
}()
_, err = io.Copy(destination, source)
if err != nil {
return fmt.Errorf("failed copying from %s to %s: %w", src, dst, err)
}
err = destination.Sync()
if err != nil {
return fmt.Errorf("failed syncing destination %s: %w", dst, err)
}
View on GitHub (pinned to bd85ce9dee)
Solutions
- Create the destination directory first (os.MkdirAll(filepath.Dir(dst), 0o755)) and check ownership
- Run the install step with sufficient privileges or chown the install directory to the running user
- Check the filesystem is writable (not mounted read-only) and has free space
- Prefer same-filesystem rename so copyFile isn't needed at all
Example fix
// before destination, err := os.Create(dst) // after (caller ensures dir exists first) os.MkdirAll(filepath.Dir(dst), 0o755) destination, err := os.Create(dst)
Defensive patterns
Strategy: validation
Validate before calling
if err := os.MkdirAll(filepath.Dir(dst), 0o755); err != nil {
return err
}
f, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE, 0o755)
if err != nil { return err }
f.Close() Try / catch
if err := installLibrary(dst); err != nil {
if strings.Contains(err.Error(), "failed create destination") {
os.MkdirAll(filepath.Dir(dst), 0o755)
return installLibrary(dst) // retry after fixing dir
}
return err
} Prevention
- Always create the destination directory before writing
- Run installs as a user with write access to the target dir
- Check for read-only mounts and full disks before install
- Prefer atomic rename within the same filesystem to skip the copy path entirely
When it happens
Trigger: os.Create(dst) fails during the copy fallback: destination directory missing, read-only filesystem, permission denied for the current user, or disk full at create time.
Common situations: Installing the BAML library into a system or plugin directory owned by root, a project cache dir deleted between steps, or read-only container filesystems.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- failed to install {} into {}
- access error: {message}
- ErrCacheDir
- failed open source %s: %w
- IO error: {0}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/40bd337389ad9633.
Report an issue: GitHub.