{"record":{"id":"40bd337389ad9633","repo":"BoundaryML/baml","slug":"failed-create-destination-s-w","errorCode":null,"errorMessage":"failed create destination %s: %w","messagePattern":"failed create destination (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/baml_go/lib_common.go","lineNumber":644,"sourceCode":"\tfor _, r := range s {\n\t\tif !((r >= '0' && r <= '9') || (r >= 'a' && r <= 'f') || (r >= 'A' && r <= 'F')) {\n\t\t\treturn false\n\t\t}\n\t}\n\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","sourceCodeStart":626,"sourceCodeEnd":662,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/lib_common.go#L626-L662","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ndestination, err := os.Create(dst)\n// after (caller ensures dir exists first)\nos.MkdirAll(filepath.Dir(dst), 0o755)\ndestination, err := os.Create(dst)","handlingStrategy":"validation","validationCode":"if err := os.MkdirAll(filepath.Dir(dst), 0o755); err != nil {\n    return err\n}\nf, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE, 0o755)\nif err != nil { return err }\nf.Close()","typeGuard":null,"tryCatchPattern":"if err := installLibrary(dst); err != nil {\n    if strings.Contains(err.Error(), \"failed create destination\") {\n        os.MkdirAll(filepath.Dir(dst), 0o755)\n        return installLibrary(dst) // retry after fixing dir\n    }\n    return err\n}","preventionTips":["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"],"tags":["filesystem","file-write","permissions","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-14T11:17:12.474Z"}