{"record":{"id":"6a3dec060fc78c99","repo":"hashicorp/nomad","slug":"couldn-t-copy-q-to-q-w","errorCode":null,"errorMessage":"Couldn't copy %q to %q: %w","messagePattern":"Couldn't copy %q to %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocdir/alloc_dir.go","lineNumber":579,"sourceCode":"\n// fileCopy from src to dst setting the permissions and owner (if uid & gid are\n// both greater than 0)\nfunc fileCopy(src, dst string, uid, gid int, perm os.FileMode) error {\n\t// Do a simple copy.\n\tsrcFile, err := os.Open(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Couldn't open src file %v: %w\", src, err)\n\t}\n\tdefer srcFile.Close()\n\n\tdstFile, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE, perm)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Couldn't create destination file %v: %w\", dst, err)\n\t}\n\tdefer dstFile.Close()\n\n\tif _, err := io.Copy(dstFile, srcFile); err != nil {\n\t\treturn fmt.Errorf(\"Couldn't copy %q to %q: %w\", src, dst, err)\n\t}\n\n\tif uid != idUnsupported && gid != idUnsupported {\n\t\tif err := dstFile.Chown(uid, gid); err != nil {\n\t\t\treturn fmt.Errorf(\"Couldn't copy %q to %q: %w\", src, dst, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// pathExists is a helper function to check if the path exists.\nfunc pathExists(path string) bool {\n\tif _, err := os.Stat(path); err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn false\n\t\t}\n\t}","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocdir/alloc_dir.go#L561-L597","documentation":"This error is returned by fileCopy in the allocdir package when io.Copy fails to copy the source file's contents into the newly created destination file. HashiCorp Nomad wraps the underlying OS error with both the source and destination paths so the operator can tell which file transfer inside an allocation directory failed. It is a generic wrapper: the real cause (disk full, I/O error, permission denied, etc.) is in the wrapped error.","triggerScenarios":"fileCopy(src, dst, perm, uid, gid) was invoked via linkOrCopy after a hard link was not possible, the destination file was created successfully, but the subsequent io.Copy(dstFile, srcFile) returned an error (read error on src or write error on dst).","commonSituations":"Disk full on the host or volume holding the allocation directory; source file unreadable due to permission changes; I/O errors on failing disks; NFS/remote filesystem failures when the alloc dir is on shared storage; copying large files that exceed quota.","solutions":["Inspect the wrapped error (%w) for the root cause and free disk space if it indicates ENOSPC.","Check read permissions on the source file and write permissions on the destination directory.","Verify the health of the underlying filesystem/volume (dmesg, SMART) if I/O errors are reported.","Retry the allocation; linkOrCopy falls back to copying when hard links fail, so transient FS issues may resolve."],"exampleFix":"// before: opaque failure with only paths\nreturn fmt.Errorf(\"Couldn't copy %q to %q: %w\", src, dst, err)\n// after (caller side): surface wrapped cause and retry transient failures\nif err := linkOrCopy(src, dst, perm, uid, gid); err != nil {\n    if errors.Is(err, syscall.ENOSPC) {\n        return fmt.Errorf(\"alloc dir full; free space and retry: %w\", err)\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// before calling the copy path\nif st, err := os.Stat(src); err != nil || st.IsDir() {\n    return fmt.Errorf(\"source unreadable or not a file: %s\", src)\n}\nif free, err := diskFree(filepath.Dir(dst)); err == nil && free < st.Size() {\n    return fmt.Errorf(\"insufficient space for %s\", dst)\n}","typeGuard":null,"tryCatchPattern":"if err := linkOrCopy(src, dst, perm, uid, gid); err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) {\n        log.Printf(\"copy failed %s->%s: op=%s path=%s: %v\", src, dst, perr.Op, perr.Path, perr.Err)\n    }\n    if errors.Is(err, syscall.ENOSPC) { /* free space / retry later */ }\n    return err\n}","preventionTips":["Monitor free space on the client data_dir volume and alert before it fills.","Keep alloc dir on a single healthy local filesystem.","Ensure the client user can read all sources it is asked to copy."],"tags":["filesystem","io","copy","nomad"],"backgroundTag":"file-copy-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}