{"record":{"id":"70fbf9580effa699","repo":"go-delve/delve","slug":"failed-to-open-file-s-w","errorCode":null,"errorMessage":"failed to open file '%s': %w","messagePattern":"failed to open file '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/command.go","lineNumber":1715,"sourceCode":"\t\t\t\tif i+1 >= len(argv) {\n\t\t\t\t\treturn errors.New(\"missing filename after -save flag\")\n\t\t\t\t}\n\t\t\t\tsaveFile = argv[i+1]\n\t\t\t\tbreak argsLoop // Exit loop since we found -save and its argument\n\t\t\t}\n\t\t}\n\t}\n\n\tbreakPoints, err := t.client.ListBreakpoints(showAll)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// If -save flag is provided, save breakpoints to file\n\tif saveFile != \"\" {\n\t\tfile, err := os.Create(saveFile)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to open file '%s': %w\", saveFile, err)\n\t\t}\n\t\tdefer file.Close()\n\t\tw := bufio.NewWriter(file)\n\t\tdefer w.Flush()\n\n\t\t// Instead of storing the ID, we label the breakpoints to\n\t\t// reference them properly in future executions\n\t\taliaser := func(bp *api.Breakpoint) string {\n\t\t\tif bp.Name == \"\" {\n\t\t\t\treturn fmt.Sprintf(\"bp%d\", bp.ID)\n\t\t\t}\n\t\t\treturn bp.Name\n\t\t}\n\n\t\tfor _, bp := range breakPoints {\n\t\t\t// We don't need to store these breakpoints\n\t\t\tif bp.ID < 0 {\n\t\t\t\tcontinue","sourceCodeStart":1697,"sourceCodeEnd":1733,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/command.go#L1697-L1733","documentation":"The `breakpoints -save <file>` command writes all breakpoints to a file so they can be restored later. It uses os.Create on the given path; if the OS refuses (bad directory, permission denied, path is a directory, too many open files, etc.), the open failure is wrapped as 'failed to open file %s: %w' with the underlying OS error attached.","triggerScenarios":"`breakpoints -save /path/file.txt` where /path does not exist, the user lacks write permission, the path names an existing directory, or the filesystem is read-only — os.Create returns an error and it is wrapped at command.go:1715.","commonSituations":"Typo in the target directory (e.g. ~/brekpoints.txt path); running dlv as a user without write access to the current directory; -save path pointing at a directory; read-only container filesystem; disk full or inode limits.","solutions":["Verify the parent directory exists (mkdir -p) and the path is not a directory itself.","Check write permissions on the target directory (ls -ld, chmod/chown as needed).","Use an absolute, correctly spelled path; quote it if it contains spaces.","If running in a container/CI, ensure the filesystem is writable and not full (df -h)."],"exampleFix":"// before\nbreakpoints -save ./missing-dir/bps.txt\n// failed to open file './missing-dir/bps.txt': open ./missing-dir/bps.txt: no such file or directory\n\n// after\nmkdir -p ./missing-dir\nbreakpoints -save ./missing-dir/bps.txt","handlingStrategy":"validation","validationCode":"// Pre-flight check before running: breakpoints -save <path>\nfunc canCreate(path string) error {\n    dir := filepath.Dir(path)\n    if fi, err := os.Stat(dir); err != nil {\n        return fmt.Errorf(\"directory %s missing: %w\", dir, err)\n    } else if !fi.IsDir() {\n        return fmt.Errorf(\"%s is not a directory\", dir)\n    }\n    if fi, err := os.Stat(path); err == nil && fi.IsDir() {\n        return fmt.Errorf(\"%s is a directory\", path)\n    }\n    f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0o644)\n    if err != nil {\n        return err\n    }\n    f.Close()\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Execute(\"breakpoints -save \" + path); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, pe) || strings.Contains(err.Error(), \"failed to open file\") {\n        fmt.Fprintf(os.Stderr, \"cannot save breakpoints: %v\\n\", err) // wrapped os error is included\n    }\n}","preventionTips":["mkdir -p the target directory before saving.","Use absolute paths and quote paths with spaces.","Check write permissions and that the path is not an existing directory.","In containers/CI, confirm the filesystem is writable and has free space."],"tags":["terminal","filesystem","io","breakpoints","delve"],"backgroundTag":"file-open-failed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}