{"record":{"id":"99ff992fb12b0f55","repo":"dgraph-io/dgraph","slug":"file-handler-failed-to-create-file-s","errorCode":null,"errorMessage":"File handler failed to create file %s","messagePattern":"File handler failed to create file (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/backup_handler.go","lineNumber":210,"sourceCode":"}\n\ntype fileSyncer struct {\n\tfp *os.File\n}\n\nfunc (fs *fileSyncer) Write(p []byte) (n int, err error) { return fs.fp.Write(p) }\nfunc (fs *fileSyncer) Close() error {\n\tif err := fs.fp.Sync(); err != nil {\n\t\treturn errors.Wrapf(err, \"while syncing file: %s\", fs.fp.Name())\n\t}\n\terr := fs.fp.Close()\n\treturn errors.Wrapf(err, \"while closing file: %s\", fs.fp.Name())\n}\n\nfunc (h *fileHandler) CreateFile(path string) (io.WriteCloser, error) {\n\tpath = h.JoinPath(path)\n\tfp, err := os.Create(path)\n\treturn &fileSyncer{fp}, errors.Wrapf(err, \"File handler failed to create file %s\", path)\n}\n\nfunc (h *fileHandler) Rename(src, dst string) error {\n\tsrc = h.JoinPath(src)\n\tdst = h.JoinPath(dst)\n\treturn os.Rename(src, dst)\n}\n\n// pathExist checks if a path (file or dir) is found at target.\n// Returns true if found, false otherwise.\nfunc pathExist(path string) bool {\n\t_, err := os.Stat(path)\n\tif err == nil {\n\t\treturn true\n\t}\n\treturn !os.IsNotExist(err) && !os.IsPermission(err)\n}\n","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/backup_handler.go#L192-L228","documentation":"fileHandler.CreateFile wraps os.Create failures with 'File handler failed to create file <path>'. It means the local handler could not open the backup file for writing at the joined path — creation/permission/path problems, not write-time failures.","triggerScenarios":"os.Create(JoinPath(path)) fails: parent directory doesn't exist (CreateDir was skipped or failed), EACCES, target name exists as a directory, ENOSPC on metadata, or invalid characters in the backup file name.","commonSituations":"Calling CreateFile without first calling CreateDir; wrong rootDir prefix in the file: URI; umask/permissions blocking the worker; a directory existing at the target file path; typo in the backup file name format.","solutions":["Ensure CreateDir was called (successfully) for the parent directory before CreateFile.","Check the wrapped os error's path/errno; fix permissions or remove the conflicting directory at that path.","Verify the file: URI rootDir and JoinPath result point where you expect (log the joined path).","Free disk space / fix read-only mounts if errno is ENOSPC or EROFS."],"exampleFix":"// before\nw, err := h.CreateFile(backupFile)\n// after\nif err := h.CreateDir(filepath.Dir(backupFile)); err != nil {\n    return nil, err\n}\nw, err := h.CreateFile(backupFile)","handlingStrategy":"validation","validationCode":"dir := filepath.Dir(backupPath)\nif info, err := os.Stat(dir); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"parent dir %s missing/not a dir before CreateFile\", dir)\n}","typeGuard":"func dirWritable(dir string) bool {\n    return unix.Access(dir, unix.W_OK) == nil\n}","tryCatchPattern":"w, err := h.CreateFile(p)\nif err != nil {\n    var pe *os.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, syscall.ENOENT) {\n        log.Printf(\"missing parent dir for %s — call CreateDir first\", pe.Path)\n    }\n    return err\n}","preventionTips":["Always pair CreateDir + CreateFile in a helper.","Validate the file: URI root at startup with a write test.","Keep backup file names within safe length/charset limits.","Run the worker as a user owning the backup root."],"tags":["filesystem","create-file","permissions"],"backgroundTag":"file-create-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}