go-delve/delve · error

could not create stdout file: %v

Error message

could not create stdout file: %v

What it means

When launch options stdoutTo/stderrTo are set, Delve creates files to capture the debuggee's stdout/stderr via a local create() helper. If creating (or reopening) the stdout target file fails, this error aborts the launch. The same pattern is checked again for stderrTo right after.

Source

Thrown at service/dap/server.go:1454

		create := func(redirect string, dflt *os.File) (f *os.File) {
			if redirect != "" {
				f, err = os.Create(redirect)
				toclose = append(toclose, f)

				return f
			}

			return dflt
		}
		defer func() {
			for _, f := range toclose {
				f.Close()
			}
		}()

		cmd.Stdout = create(stdoutTo, os.Stdout)
		if err != nil {
			return nil, nil, nil, fmt.Errorf("could not create stdout file: %v", err)
		}

		cmd.Stderr = create(stderrTo, os.Stderr)
		if err != nil {
			return nil, nil, nil, fmt.Errorf("could not create stderr file: %v", err)
		}
	}

	if err = cmd.Start(); err != nil {
		return nil, nil, nil, err
	}

	s.noDebugProcess = &process{Cmd: cmd, exited: make(chan struct{})}
	return cmd, stdoutReader, stderrReader, nil
}

// stopNoDebugProcess is called from Stop (main goroutine) and
// onDisconnectRequest (run goroutine) and requires holding mu lock.

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Create the parent directory of stdoutTo first (mkdir -p) and confirm it is writable by the delve process user.
  2. Check that stdoutTo is a file path, not an existing directory.
  3. Verify filesystem permissions/ownership, especially in containers or when dlv runs under a different user than the IDE.
  4. Omit stdoutTo/stderrTo if you want output in the debug console instead of files.

Example fix

// before (launch.json)
"stdoutTo": "/var/log/delve/out.log"  // /var/log/delve missing
// after
"stdoutTo": "/tmp/delve/out.log"  // after mkdir -p /tmp/delve
Defensive patterns

Strategy: validation

Validate before calling

for _, p := range []string{cfg.StdoutTo, cfg.StderrTo} {
    if p == "" {
        continue
    }
    dir := filepath.Dir(p)
    if fi, err := os.Stat(dir); err != nil || !fi.IsDir() {
        if err := os.MkdirAll(dir, 0o755); err != nil {
            return fmt.Errorf("cannot create dir for %s: %w", p, err)
        }
    }
    if fi, err := os.Stat(p); err == nil && fi.IsDir() {
        return fmt.Errorf("%s is a directory, need a file path", p)
    }
}

Prevention

When it happens

Trigger: A DAP launch request with stdoutTo set to a path in a nonexistent directory, a write-protected location, a directory itself, or a path the delve process cannot create due to permissions or a read-only filesystem.

Common situations: Redirecting output to '/tmp/logs/dlv.out' where the logs directory doesn't exist; read-only container filesystems; paths owned by another user; Windows-style paths on Linux or vice versa; stale paths from a copied launch configuration.

Related errors


AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31). Data as JSON: /api/errors/aafeb819a7807de3. Report an issue: GitHub.