go-delve/delve · error

failed to write breakpoint to file %s:%d

Error message

failed to write breakpoint to file %s:%d

What it means

While saving breakpoints with `breakpoints -save`, each breakpoint is serialized as a `break`/`trace` (and `condition`) line via fmt.Fprintf into the buffered writer. If a write fails — typically a full disk, closed/errored file, or I/O error — Delve reports 'failed to write breakpoint to file <file>:<line>' identifying which breakpoint could not be persisted. Note the underlying error is not wrapped here, only the breakpoint location is reported.

Source

Thrown at pkg/terminal/command.go:1747

		for _, bp := range breakPoints {
			// We don't need to store these breakpoints
			if bp.ID < 0 {
				continue
			}
			// Skip watchpoints as they can't be reliably restored
			if bp.WatchExpr != "" {
				continue
			}

			var err error
			if bp.Tracepoint {
				_, err = fmt.Fprintf(w, "trace %s %s:%d\n", aliaser(bp), bp.File, bp.Line)
			} else {
				_, err = fmt.Fprintf(w, "break %s %s:%d\n", aliaser(bp), bp.File, bp.Line)
			}
			if err != nil {
				return fmt.Errorf("failed to write breakpoint to file %s:%d", bp.File, bp.Line)
			}
			if len(bp.Cond) > 0 {
				_, err = fmt.Fprintf(w, "condition %s %s\n", aliaser(bp), bp.Cond)
				if err != nil {
					return fmt.Errorf("failed to write condition to file %d:%s", bp.ID, bp.Cond)
				}
			}
			if bp.HitCond != "" {
				if bp.HitCondPerG {
					_, err = fmt.Fprintf(w, "condition -per-g-hitcount %s %s\n", aliaser(bp), bp.HitCond)
				} else {
					_, err = fmt.Fprintf(w, "condition -hitcount %s %s\n", aliaser(bp), bp.HitCond)
				}
				if err != nil {
					return fmt.Errorf("failed to write hit condition to file %d:%s", bp.ID, bp.HitCond)
				}
			}
			if bp.Disabled {

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Check free disk space (df -h) and quota, then retry `breakpoints -save`.
  2. Verify the output file/mount is still writable and connected.
  3. Retry the save to a different local path.
  4. If a specific breakpoint's condition is enormous, shorten it before saving.

Example fix

// before
breakpoints -save /mnt/usb/bps.txt   // /mnt/usb disconnected mid-write
// failed to write breakpoint to file /app/main.go:42

// after
breakpoints -save /home/user/bps.txt // local writable path
Defensive patterns

Strategy: fallback

Validate before calling

// Check writable space before saving many breakpoints
if fi, err := os.Statfs(dir); err == nil && fi.Bavail*uint64(fi.Bsize) < 1<<20 {
    return errors.New("less than 1MB free, save may fail")
}

Try / catch

if err := cmd.Execute("breakpoints -save " + path); err != nil {
    if strings.Contains(err.Error(), "failed to write breakpoint to file") {
        // fall back to a different local path and retry
        fallback := filepath.Join(os.TempDir(), "dlv-bps.txt")
        cmd.Execute("breakpoints -save " + fallback)
    }
}

Prevention

When it happens

Trigger: Saving many/very long breakpoints or conditions when the disk is full or the file descriptor has failed mid-write; bufio.Flush errors are deferred so the mid-loop Fprintf error path at command.go:1747 fires when the writer errors.

Common situations: Disk quota exceeded during a long debugging session; saving to a removable/network mount that disconnected; ulimit on file size; saving hundreds of breakpoints with very long condition expressions.

Related errors


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