dgraph-io/dgraph · error

error while creating debug file: %s

Error message

error while creating debug file: %s

What it means

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.

Source

Thrown at dgraph/cmd/debuginfo/debugging.go:73

	glog.Infof("fetching information over HTTP from %s", sourceURL)
	if duration > 0 {
		glog.Info(fmt.Sprintf("please wait... (%v)", duration))
	}

	timeout := duration + duration/2 + 2*time.Second
	resp, err = fetchURL(sourceURL, timeout)
	if err != nil {
		return err
	}
	defer func() {
		if err := resp.Close(); err != nil {
			glog.Warningf("error closing resp reader: %v", err)
		}
	}()
	out, err := os.Create(filePath)
	if err != nil {
		return fmt.Errorf("error while creating debug file: %s", err)
	}
	defer func() {
		out.Close()
	}()
	_, err = io.Copy(out, resp)
	return err
}

// fetchURL fetches a profile from a URL using HTTP.
func fetchURL(source string, timeout time.Duration) (io.ReadCloser, error) {
	client := &http.Client{
		Timeout: timeout,
	}
	resp, err := client.Get(source)
	if err != nil {
		return nil, fmt.Errorf("http fetch: %v", err)
	}
	if resp.StatusCode != http.StatusOK {

View on GitHub (pinned to 759e242be6)

Solutions

  1. Ensure the output directory exists and is writable (mkdir -p; check ls -ld)
  2. Check available disk space (df -h) and file permissions on the target path
  3. Run dgraph debuginfo with a user that has write access, or pass --output to a writable location

Example fix

// before
dgraph debuginfo --output /root/debug  # dir missing
// error while creating debug file: open /root/debug/...: no such file or directory
// after
mkdir -p /root/debug && dgraph debuginfo --output /root/debug
Defensive patterns

Strategy: try-catch

Validate before calling

func ensureWritable(path string) error {
    dir := filepath.Dir(path)
    if err := os.MkdirAll(dir, 0o755); err != nil { return err }
    f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0o644)
    if err != nil { return err }
    return f.Close()
}
// run before dgraph debuginfo to fail fast with a clear message

Try / catch

// Go: when embedding saveDebug-equivalent logic
out, err := os.Create(filePath)
if err != nil {
    return fmt.Errorf("error while creating debug file: %s", err)
}
// CLI users: check the wrapped cause (no such file / permission denied / no space)
// and fix path, permissions, or disk space, then rerun dgraph debuginfo.

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/1a8bb10dc3fd7526. Report an issue: GitHub.