BoundaryML/baml · error
failed close destination
Error message
failed close destination %s: %w
What it means
This error is produced by copyFile in baml_go/lib_common.go when closing the destination file (via defer) fails after the copy itself succeeded. The library wraps Close errors so callers learn the copied file may not be fully persisted/released. It only surfaces if no earlier error occurred (err == nil at defer time).
Solutions
- Check free disk space on the destination volume and retry
- Verify the destination directory/filesystem is writable and healthy (not read-only, not NFS with stale locks)
- Re-run the download; the library re-downloads the native client artifact
- If persistent, clear the partially written destination file before retrying
Example fix
// before (disk full)
cerr := destination.Close() // "no space left on device" -> failed close destination
// after (ensure space before copy)
if stat, err := os.Stat(filepath.Dir(dst)); err == nil {
if usage := checkFreeSpace(stat); usage < requiredBytes {
return fmt.Errorf("insufficient disk space at %s", filepath.Dir(dst))
}
} Defensive patterns
Strategy: try-catch
Validate before calling
if usage, err := diskUsage(filepath.Dir(dst)); err == nil && usage < requiredBytes {
return fmt.Errorf("insufficient disk space for %s", dst)
} Try / catch
if err := baml.DownloadLibrary(dst); err != nil {
if strings.Contains(err.Error(), "failed close destination") {
// recover: free space / remount, delete partial dst, retry once
os.Remove(dst)
}
return err
} Prevention
- Monitor free disk space before running first-time native downloads
- Keep the library cache on a healthy local (non-network, non-noexec) filesystem
- Treat close/sync errors as data-integrity signals — delete partial files on failure
When it happens
Trigger: downloadBamlLibrary calls copyFile; io.Copy succeeds but destination.Close() returns an error (e.g. disk full detected on close, NFS/overlayfs flush failure, file lock issues).
Common situations: Full or flaky disk when downloading the BAML native library on first run; containers with read-only or nearly-full writable layers; network filesystems where Close can fail after writes appear successful.
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 copying from to
- failed syncing destination
- decodeCheckedValue: valueChecked is nil
- decodeLiteralValue: valueLiteral is nil
- decodeRawObjectImpl is not set. Please call…
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/e4ab541d4cec83b7.
Report an issue: GitHub.
Appendix: source
Thrown at engine/language_client_go/baml_go/lib_common.go:649
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)
}
logger.Debug("File copied successfully", "source", src, "destination", dst)
return nil
}
func isSupportedPlatform() bool {View on GitHub (pinned to bd85ce9dee)