{"record":{"id":"aafeb819a7807de3","repo":"go-delve/delve","slug":"could-not-create-stdout-file-v","errorCode":null,"errorMessage":"could not create stdout file: %v","messagePattern":"could not create stdout file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/dap/server.go","lineNumber":1454,"sourceCode":"\t\tcreate := func(redirect string, dflt *os.File) (f *os.File) {\n\t\t\tif redirect != \"\" {\n\t\t\t\tf, err = os.Create(redirect)\n\t\t\t\ttoclose = append(toclose, f)\n\n\t\t\t\treturn f\n\t\t\t}\n\n\t\t\treturn dflt\n\t\t}\n\t\tdefer func() {\n\t\t\tfor _, f := range toclose {\n\t\t\t\tf.Close()\n\t\t\t}\n\t\t}()\n\n\t\tcmd.Stdout = create(stdoutTo, os.Stdout)\n\t\tif err != nil {\n\t\t\treturn nil, nil, nil, fmt.Errorf(\"could not create stdout file: %v\", err)\n\t\t}\n\n\t\tcmd.Stderr = create(stderrTo, os.Stderr)\n\t\tif err != nil {\n\t\t\treturn nil, nil, nil, fmt.Errorf(\"could not create stderr file: %v\", err)\n\t\t}\n\t}\n\n\tif err = cmd.Start(); err != nil {\n\t\treturn nil, nil, nil, err\n\t}\n\n\ts.noDebugProcess = &process{Cmd: cmd, exited: make(chan struct{})}\n\treturn cmd, stdoutReader, stderrReader, nil\n}\n\n// stopNoDebugProcess is called from Stop (main goroutine) and\n// onDisconnectRequest (run goroutine) and requires holding mu lock.","sourceCodeStart":1436,"sourceCodeEnd":1472,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/dap/server.go#L1436-L1472","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Create the parent directory of stdoutTo first (mkdir -p) and confirm it is writable by the delve process user.","Check that stdoutTo is a file path, not an existing directory.","Verify filesystem permissions/ownership, especially in containers or when dlv runs under a different user than the IDE.","Omit stdoutTo/stderrTo if you want output in the debug console instead of files."],"exampleFix":"// before (launch.json)\n\"stdoutTo\": \"/var/log/delve/out.log\"  // /var/log/delve missing\n// after\n\"stdoutTo\": \"/tmp/delve/out.log\"  // after mkdir -p /tmp/delve","handlingStrategy":"validation","validationCode":"for _, p := range []string{cfg.StdoutTo, cfg.StderrTo} {\n    if p == \"\" {\n        continue\n    }\n    dir := filepath.Dir(p)\n    if fi, err := os.Stat(dir); err != nil || !fi.IsDir() {\n        if err := os.MkdirAll(dir, 0o755); err != nil {\n            return fmt.Errorf(\"cannot create dir for %s: %w\", p, err)\n        }\n    }\n    if fi, err := os.Stat(p); err == nil && fi.IsDir() {\n        return fmt.Errorf(\"%s is a directory, need a file path\", p)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["mkdir -p the output directory before launching","Verify the path is writable by the user running delve","Skip stdoutTo/stderrTo to keep output in the debug console"],"tags":["dap","launch","file-io"],"backgroundTag":"file-create-failed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}