{"record":{"id":"e4ab541d4cec83b7","repo":"BoundaryML/baml","slug":"failed-close-destination-s-w","errorCode":null,"errorMessage":"failed close destination %s: %w","messagePattern":"failed close destination (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/baml_go/lib_common.go","lineNumber":649,"sourceCode":"\treturn true\n}\n\nfunc copyFile(src, dst string) (err error) {\n\tlogger.Debug(\"Attempting to copy file\", \"source\", src, \"destination\", dst)\n\tsource, err := os.Open(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed open source %s: %w\", src, err)\n\t}\n\tdefer source.Close()\n\n\tdestination, err := os.Create(dst)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed create destination %s: %w\", dst, err)\n\t}\n\tdefer func() {\n\t\tcerr := destination.Close()\n\t\tif err == nil && cerr != nil {\n\t\t\terr = fmt.Errorf(\"failed close destination %s: %w\", dst, cerr)\n\t\t}\n\t}()\n\n\t_, err = io.Copy(destination, source)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed copying from %s to %s: %w\", src, dst, err)\n\t}\n\n\terr = destination.Sync()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed syncing destination %s: %w\", dst, err)\n\t}\n\n\tlogger.Debug(\"File copied successfully\", \"source\", src, \"destination\", dst)\n\treturn nil\n}\n\nfunc isSupportedPlatform() bool {","sourceCodeStart":631,"sourceCodeEnd":667,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/lib_common.go#L631-L667","documentation":"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).","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before (disk full)\ncerr := destination.Close() // \"no space left on device\" -> failed close destination\n// after (ensure space before copy)\nif stat, err := os.Stat(filepath.Dir(dst)); err == nil {\n    if usage := checkFreeSpace(stat); usage < requiredBytes {\n        return fmt.Errorf(\"insufficient disk space at %s\", filepath.Dir(dst))\n    }\n}","handlingStrategy":"try-catch","validationCode":"if usage, err := diskUsage(filepath.Dir(dst)); err == nil && usage < requiredBytes {\n    return fmt.Errorf(\"insufficient disk space for %s\", dst)\n}","typeGuard":null,"tryCatchPattern":"if err := baml.DownloadLibrary(dst); err != nil {\n    if strings.Contains(err.Error(), \"failed close destination\") {\n        // recover: free space / remount, delete partial dst, retry once\n        os.Remove(dst)\n    }\n    return err\n}","preventionTips":["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"],"tags":["go","file-io","native-library-download"],"backgroundTag":"file-write-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}