{"record":{"id":"bf615078b18785dc","repo":"go-delve/delve","slug":"could-not-rebuild-process-s","errorCode":null,"errorMessage":"could not rebuild process: %s","messagePattern":"could not rebuild process: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/debugger/debugger.go","lineNumber":531,"sourceCode":"\n\tif err := d.detach(true); err != nil {\n\t\treturn nil, err\n\t}\n\tif resetArgs {\n\t\td.processArgs = append([]string{d.processArgs[0]}, newArgs...)\n\t\td.config.Stdin = newRedirects[0]\n\t\td.config.Stdout = proc.OutputRedirect{Path: newRedirects[1]}\n\t\td.config.Stderr = proc.OutputRedirect{Path: newRedirects[2]}\n\t}\n\tvar grp *proc.TargetGroup\n\tvar err error\n\n\tif rebuild {\n\t\tswitch d.config.ExecuteKind {\n\t\tcase ExecutingGeneratedFile:\n\t\t\terr = gobuild.GoBuild(d.processArgs[0], d.config.Packages, d.config.BuildFlags)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"could not rebuild process: %s\", err)\n\t\t\t}\n\t\tcase ExecutingGeneratedTest:\n\t\t\terr = gobuild.GoTestBuild(d.processArgs[0], d.config.Packages, d.config.BuildFlags)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"could not rebuild process: %s\", err)\n\t\t\t}\n\t\tdefault:\n\t\t\t// We cannot build a process that we didn't start, because we don't know how it was built.\n\t\t\treturn nil, errors.New(\"cannot rebuild a binary\")\n\t\t}\n\t}\n\n\tif recorded {\n\t\trun, stop, err2 := gdbserial.RecordAsync(d.processArgs, d.config.WorkingDir, false, d.config.Stdin, d.config.Stdout, d.config.Stderr)\n\t\tif err2 != nil {\n\t\t\treturn nil, err2\n\t\t}\n","sourceCodeStart":513,"sourceCodeEnd":549,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/debugger/debugger.go#L513-L549","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (broken code edited mid-session)\nfmt.Println(x) // undefined: x\n// after\nx := computeX()\nfmt.Println(x)\n// then: dlv restart -r","handlingStrategy":"try-catch","validationCode":"// pre-check the package compiles before Restart(rebuild=true)\ncmd := exec.Command(\"go\", \"build\", \"./...\")\nif err := cmd.Run(); err != nil {\n    return fmt.Errorf(\"fix compile errors before restart: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"grp, err := dbg.Restart(rebuild)\nif err != nil && strings.HasPrefix(err.Error(), \"could not rebuild process:\") {\n    // surface the inner go build error to the user / editor problems panel\n    return parseCompilerErrors(err)\n}","preventionTips":["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."],"tags":["build","go-compiler","restart","rebuild"],"backgroundTag":"go-build-failed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}