{"record":{"id":"8ae3624457eb474f","repo":"go-delve/delve","slug":"invalid-process-id-d","errorCode":null,"errorMessage":"invalid process ID: %d","messagePattern":"invalid process ID: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/debugger/debugger.go","lineNumber":177,"sourceCode":"\tDisableASLR bool\n\n\tRrOnProcessPid int\n\tRrDelOnDetach  bool\n}\n\n// New creates a new Debugger. ProcessArgs specify the commandline arguments for the\n// new process.\nfunc New(config *Config, processArgs []string) (*Debugger, error) {\n\tlogger := logflags.DebuggerLogger()\n\td := &Debugger{\n\t\tconfig:      config,\n\t\tprocessArgs: processArgs,\n\t\tlog:         logger,\n\t}\n\n\t// Validate AttachPid if specified\n\tif d.config.AttachPid != 0 && d.config.AttachPid < 0 {\n\t\treturn nil, fmt.Errorf(\"invalid process ID: %d\", d.config.AttachPid)\n\t}\n\n\t// Create the process by either attaching or launching.\n\tswitch {\n\tcase d.config.AttachPid > 0 || d.config.AttachWaitFor != \"\":\n\t\td.log.Infof(\"attaching to pid %d\", d.config.AttachPid)\n\t\tpath := \"\"\n\t\tif len(d.processArgs) > 0 {\n\t\t\tpath = d.processArgs[0]\n\t\t}\n\t\tvar waitFor *proc.WaitFor\n\t\tif d.config.AttachWaitFor != \"\" {\n\t\t\twaitFor = &proc.WaitFor{\n\t\t\t\tName:     d.config.AttachWaitFor,\n\t\t\t\tInterval: time.Duration(d.config.AttachWaitForInterval * float64(time.Millisecond)),\n\t\t\t\tDuration: time.Duration(d.config.AttachWaitForDuration * float64(time.Millisecond)),\n\t\t\t}\n\t\t}","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/debugger/debugger.go#L159-L195","documentation":"When creating a debugger in attach mode, a negative AttachPid is invalid (0 means 'not attaching'). New() validates this before attempting any process operation and rejects the configuration.","triggerScenarios":"dlv attach with a negative PID, or programmatic construction of service.Config with AttachPid set to a negative value.","commonSituations":"Scripts passing shell variables that are empty or negative into attach commands; arithmetic producing negative PIDs; UI clients sending -1 as a placeholder.","solutions":["Pass a real positive PID from `ps` or `pgrep`","Check the script/variable feeding the PID for empty/invalid values","Leave AttachPid at 0 (unset) when launching instead of attaching","Guard the value before calling New/debugger creation"],"exampleFix":"// before\ncfg.AttachPid = pid // pid may be -1\n// after\nif pid <= 0 { return fmt.Errorf(\"need a positive pid, got %d\", pid) }\ncfg.AttachPid = pid","handlingStrategy":"validation","validationCode":"func validateAttachPid(pid int) error { if pid < 0 { return fmt.Errorf(\"invalid process ID: %d\", pid) }; return nil }","typeGuard":"func isAttachablePid(pid int) bool { return pid > 0 }","tryCatchPattern":"if _, err := debugger.New(config, logger); err != nil { if strings.Contains(err.Error(), \"invalid process ID\") { /* resolve a real pid and retry */ } return err }","preventionTips":["Resolve PIDs via pgrep/ps before attaching","Guard shell variables that may be empty/negative","Leave AttachPid unset (0) for launch mode"],"tags":["attach","process","validation"],"backgroundTag":"invalid-process-id","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}