{"record":{"id":"b20b0ba6ea582497","repo":"go-delve/delve","slug":"process-d-has-exited-with-status-d","errorCode":null,"errorMessage":"Process %d has exited with status %d","messagePattern":"Process (.+?) has exited with status (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/command.go","lineNumber":1457,"sourceCode":"\t\tcase \"f\", \"c\", \"s\":\n\t\t\treturn answer, nil\n\t\t}\n\t}\n}\n\nfunc scopePrefixSwitch(t *Term, ctx callContext) error {\n\tif ctx.Scope.GoroutineID > 0 {\n\t\t_, err := t.client.SwitchGoroutine(ctx.Scope.GoroutineID)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc exitedToError(state *api.DebuggerState, err error) (*api.DebuggerState, error) {\n\tif err == nil && state.Exited {\n\t\treturn nil, fmt.Errorf(\"Process %d has exited with status %d\", state.Pid, state.ExitStatus)\n\t}\n\treturn state, err\n}\n\nfunc (c *Commands) step(t *Term, ctx callContext, args string) error {\n\tif err := scopePrefixSwitch(t, ctx); err != nil {\n\t\treturn err\n\t}\n\tc.frame = 0\n\tstepfn := t.client.Step\n\tif ctx.Prefix == revPrefix {\n\t\tstepfn = t.client.ReverseStep\n\t}\n\tstate, err := exitedToError(stepfn())\n\tif err != nil {\n\t\tprintcontextNoState(t)\n\t\treturn err\n\t}","sourceCodeStart":1439,"sourceCodeEnd":1475,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/command.go#L1439-L1475","documentation":"exitedToError converts an api.DebuggerState that reports Exited into an error, because most stepping commands (step, stepInstruction, next, stepout, call) cannot proceed on a dead process. When the RPC returns no error but state.Exited is true, Delve surfaces 'Process %d has exited with status %d' instead of returning a state that callers cannot act on.","triggerScenarios":"Any of step, next, stepout, stepInstruction, call executed after the debugged program has terminated (e.g. the program ran to completion or called os.Exit), so the returned state has Exited=true with ExitStatus set.","commonSituations":"Hitting Enter on `next` repeatedly until the program finishes, then stepping once more; a `call` expression terminates the process; scripted terminal sessions blindly issue step commands after the program exits.","solutions":["Check state.Exited (or run `exitStatus`) before issuing further stepping commands.","Restart the session (`restart` or relaunch) before continuing to debug.","Set a breakpoint near program end if you need to inspect state before termination.","Wrap scripted command sequences to stop on this error rather than continuing to step."],"exampleFix":"// before\nstate, err := client.GetState()\n// then blindly: cmd.step(...)\n\n// after\nstate, err := client.GetState()\nif err == nil && state.Exited {\n    fmt.Println(\"process already exited, restart first\")\n    return\n}\n// then: cmd.step(...)","handlingStrategy":"type-guard","validationCode":"// Before stepping, confirm the process is still alive\nstate, err := client.GetState()\nif err != nil {\n    return err\n}\nif state.Exited {\n    return fmt.Errorf(\"process %d already exited (status %d); restart before stepping\", state.Pid, state.ExitStatus)\n}","typeGuard":"func processAlive(s *api.DebuggerState) bool {\n    return s != nil && !s.Exited\n}","tryCatchPattern":"state, err := cmd.step(...)\nif err != nil && strings.Contains(err.Error(), \"has exited with status\") {\n    // recover: restart or stop the scripted session\n    fmt.Fprintln(os.Stderr, err)\n    return errStopSession\n}","preventionTips":["Check state.Exited after every continue/step before issuing the next command.","Use breakpoints near program end instead of stepping past termination.","In scripted sessions, break the loop on any step error.","Call `exitStatus`/inspect state after continue to detect termination early."],"tags":["terminal","process-exit","debugger-state","delve"],"backgroundTag":"process-already-exited","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}