go-delve/delve · error
could not rebuild process: %s
Error message
could not rebuild process: %s
What it means
When restarting a debug session (dlv restart --rebuild or Restart with rebuild=true) and the original process was launched from delve-generated code (ExecutingGeneratedFile), delve re-runs `go build` via gobuild.GoBuild. If the Go compiler reports errors, Restart aborts with "could not rebuild process: <compiler output>". The inner error is the actual go build failure.
Source
Thrown at service/debugger/debugger.go:531
if err := d.detach(true); err != nil {
return nil, err
}
if resetArgs {
d.processArgs = append([]string{d.processArgs[0]}, newArgs...)
d.config.Stdin = newRedirects[0]
d.config.Stdout = proc.OutputRedirect{Path: newRedirects[1]}
d.config.Stderr = proc.OutputRedirect{Path: newRedirects[2]}
}
var grp *proc.TargetGroup
var err error
if rebuild {
switch d.config.ExecuteKind {
case ExecutingGeneratedFile:
err = gobuild.GoBuild(d.processArgs[0], d.config.Packages, d.config.BuildFlags)
if err != nil {
return nil, fmt.Errorf("could not rebuild process: %s", err)
}
case ExecutingGeneratedTest:
err = gobuild.GoTestBuild(d.processArgs[0], d.config.Packages, d.config.BuildFlags)
if err != nil {
return nil, fmt.Errorf("could not rebuild process: %s", err)
}
default:
// We cannot build a process that we didn't start, because we don't know how it was built.
return nil, errors.New("cannot rebuild a binary")
}
}
if recorded {
run, stop, err2 := gdbserial.RecordAsync(d.processArgs, d.config.WorkingDir, false, d.config.Stdin, d.config.Stdout, d.config.Stderr)
if err2 != nil {
return nil, err2
}
View on GitHub (pinned to a23773e6c3)
Solutions
- Fix the Go compile errors shown after the colon in the message, then restart again with rebuild.
- Restart without rebuild (`dlv restart` without -r) to reuse the existing binary while fixing the code.
- Check d.config.BuildFlags / build flags config for stale flags (e.g. removed -tags).
- Run `go build ./...` manually to see and fix the full error output.
Example fix
// before (broken code edited mid-session) fmt.Println(x) // undefined: x // after x := computeX() fmt.Println(x) // then: dlv restart -r
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check the package compiles before Restart(rebuild=true)
cmd := exec.Command("go", "build", "./...")
if err := cmd.Run(); err != nil {
return fmt.Errorf("fix compile errors before restart: %w", err)
} Try / catch
grp, err := dbg.Restart(rebuild)
if err != nil && strings.HasPrefix(err.Error(), "could not rebuild process:") {
// surface the inner go build error to the user / editor problems panel
return parseCompilerErrors(err)
} Prevention
- Format/save a compiling state before issuing restart --rebuild.
- Run go build/go vet in the editor on save.
- Avoid putting experimental edits between rebuild restarts; use plain restart meanwhile.
When it happens
Trigger: Calling Debugger.Restart with rebuild=true after editing source files that no longer compile; `dlv restart -r` at the terminal while the package has compile errors; ExecutingGeneratedFile restart path invoking gobuild.GoBuild with d.config.Packages and BuildFlags.
Common situations: Editing code during a debug session and saving a broken intermediate state before restarting; build flags in .delverc or launch config conflicting with current code; missing imports after refactor; Go toolchain version mismatch causing new compile errors.
Related errors
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/bf615078b18785dc.
Report an issue: GitHub.