{"record":{"id":"e033d8bea89aceb8","repo":"benfred/py-spy","slug":"invalid-pid","errorCode":null,"errorMessage":"invalid pid","messagePattern":"invalid pid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config.rs","lineNumber":455,"sourceCode":"        match subcommand {\n            \"record\" | \"top\" => {\n                config.python_program = matches\n                    .get_many::<String>(\"python_program\")\n                    .map(|vals| vals.map(|v| v.to_owned()).collect());\n                config.gil_only = matches.get_flag(\"gil\");\n                config.include_idle = matches.get_flag(\"idle\");\n            }\n            _ => {}\n        }\n\n        config.subprocesses = matches.get_flag(\"subprocesses\");\n        config.command = subcommand.to_owned();\n\n        // options that can be shared between subcommands\n        config.pid = matches.get_one::<String>(\"pid\").map(|p| {\n            // allow pid to be specified as a hexadecimal value\n            match p.to_lowercase().strip_prefix(\"0x\") {\n                Some(prefix) => Pid::from_str_radix(prefix, 16).expect(\"invalid pid\"),\n                None => p.parse().expect(\"invalid pid\"),\n            }\n        });\n\n        config.full_filenames = matches.get_flag(\"full_filenames\");\n        if cfg!(feature = \"unwind\") {\n            config.native = matches.get_flag(\"native\");\n        }\n\n        config.capture_output = config.command != \"record\" || matches.get_flag(\"capture\");\n        if !config.capture_output {\n            config.hide_progress = true;\n        }\n\n        if matches.get_flag(\"nonblocking\") {\n            // disable native profiling if invalidly asked for\n            if config.native {\n                eprintln!(\"Can't get native stack traces with the --nonblocking option.\");","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/benfred/py-spy/blob/32080cc0c22bc23938541dfa7dabb6090e40be14/src/config.rs#L437-L473","documentation":"The --pid option is parsed in Config::from_args. If the value has a \"0x\" prefix it is parsed as hexadecimal with Pid::from_str_radix, otherwise as decimal; either failure panics with \"invalid pid\" because the string is not a valid process id.","triggerScenarios":"Running any py-spy subcommand with `--pid <value>` where value is not a decimal number (and, with the 0x prefix, not valid hex) — e.g. `--pid 12a4` without 0x, `--pid 0xZZ`, `--pid \"\"`, or a negative number like `--pid -1`.","commonSituations":"Copy-pasting a pid that includes surrounding text, accidentally omitting the 0x prefix on a hex pid (Windows Device Manager / tools that show hex pids), or passing a variable that is empty in a script.","solutions":["Pass the pid as a plain decimal number from `ps`/Task Manager, e.g. `py-spy dump --pid 1234`.","If the pid is hexadecimal, keep the 0x prefix: `py-spy dump --pid 0x4d2` (equivalent to 1234).","On Windows, verify Task Manager's Details tab PID (decimal); beware tools that report hex pids.","Sanitize/validate the pid variable in shell scripts before invoking py-spy."],"exampleFix":"// before: hex pid without prefix\npy-spy dump --pid 1a2b   # panic: invalid pid\n// after\npy-spy dump --pid 0x1a2b  # or decimal 6699","handlingStrategy":"validation","validationCode":"case \"$PID\" in\n  0x*) : ;;\n  ''|*[!0-9]*) echo \"--pid must be decimal (or 0x hex)\" >&2; exit 1 ;;\nesac","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve pids with pgrep/ps and pass plain decimal numbers.","Keep the 0x prefix when the pid is hexadecimal.","Quote and trim shell variables; never pass process names as --pid."],"tags":["cli","argument-parsing","pid","panic"],"backgroundTag":"invalid-pid-argument","analyzedSha":"32080cc0c22bc23938541dfa7dabb6090e40be14","analyzedAt":"2026-09-05T19:30:55.142Z","contentChangedAt":"2026-09-05T19:30:55.142Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}