{"record":{"id":"1a8bb10dc3fd7526","repo":"dgraph-io/dgraph","slug":"error-while-creating-debug-file-s","errorCode":null,"errorMessage":"error while creating debug file: %s","messagePattern":"error while creating debug file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dgraph/cmd/debuginfo/debugging.go","lineNumber":73,"sourceCode":"\n\tglog.Infof(\"fetching information over HTTP from %s\", sourceURL)\n\tif duration > 0 {\n\t\tglog.Info(fmt.Sprintf(\"please wait... (%v)\", duration))\n\t}\n\n\ttimeout := duration + duration/2 + 2*time.Second\n\tresp, err = fetchURL(sourceURL, timeout)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer func() {\n\t\tif err := resp.Close(); err != nil {\n\t\t\tglog.Warningf(\"error closing resp reader: %v\", err)\n\t\t}\n\t}()\n\tout, err := os.Create(filePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error while creating debug file: %s\", err)\n\t}\n\tdefer func() {\n\t\tout.Close()\n\t}()\n\t_, err = io.Copy(out, resp)\n\treturn err\n}\n\n// fetchURL fetches a profile from a URL using HTTP.\nfunc fetchURL(source string, timeout time.Duration) (io.ReadCloser, error) {\n\tclient := &http.Client{\n\t\tTimeout: timeout,\n\t}\n\tresp, err := client.Get(source)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"http fetch: %v\", err)\n\t}\n\tif resp.StatusCode != http.StatusOK {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dgraph/cmd/debuginfo/debugging.go#L55-L91","documentation":"saveDebug fetches a URL (via fetchURL) and writes the response body to a local debug file. If os.Create(filePath) fails — the target path can't be opened for writing — the error is wrapped as 'error while creating debug file: %s' and returned to saveMetrics.","triggerScenarios":"Running `dgraph debuginfo` (which calls saveMetrics -> saveDebug) when the output directory doesn't exist, the target file exists with no write permission, the path is a directory, or the disk is full/read-only.","commonSituations":"Custom --output flag pointing to a non-existent or read-only path, running as a non-root user while targeting a root-owned dir, or SELinux/container permission restrictions on the mount.","solutions":["Ensure the output directory exists and is writable (mkdir -p; check ls -ld)","Check available disk space (df -h) and file permissions on the target path","Run dgraph debuginfo with a user that has write access, or pass --output to a writable location"],"exampleFix":"// before\ndgraph debuginfo --output /root/debug  # dir missing\n// error while creating debug file: open /root/debug/...: no such file or directory\n// after\nmkdir -p /root/debug && dgraph debuginfo --output /root/debug","handlingStrategy":"try-catch","validationCode":"func ensureWritable(path string) error {\n    dir := filepath.Dir(path)\n    if err := os.MkdirAll(dir, 0o755); err != nil { return err }\n    f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0o644)\n    if err != nil { return err }\n    return f.Close()\n}\n// run before dgraph debuginfo to fail fast with a clear message","typeGuard":null,"tryCatchPattern":"// Go: when embedding saveDebug-equivalent logic\nout, err := os.Create(filePath)\nif err != nil {\n    return fmt.Errorf(\"error while creating debug file: %s\", err)\n}\n// CLI users: check the wrapped cause (no such file / permission denied / no space)\n// and fix path, permissions, or disk space, then rerun dgraph debuginfo.","preventionTips":["Always mkdir -p the --output directory before running dgraph debuginfo","Run as a user with write access to the target path","Monitor disk space on the node before collecting debug info"],"tags":["file-io","filesystem","permissions","cli"],"backgroundTag":"file-write-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}