{"record":{"id":"035c3f77fc7b2e75","repo":"benfred/py-spy","slug":"invalid-duration","errorCode":null,"errorMessage":"invalid duration","messagePattern":"invalid duration","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config.rs","lineNumber":395,"sourceCode":"        let mut config = Config::default();\n\n        let (subcommand, matches) = matches.subcommand().unwrap();\n\n        // Check if `--native` was used on an unsupported platform\n        if subcommand != \"completions\" && !cfg!(feature = \"unwind\") && matches.get_flag(\"native\") {\n            eprintln!(\n                \"Collecting stack traces from native extensions (`--native`) is not supported on your platform.\"\n            );\n            std::process::exit(1);\n        }\n\n        match subcommand {\n            \"record\" => {\n                config.sampling_rate = *matches.get_one(\"rate\").unwrap();\n                config.duration = match matches.get_one::<String>(\"duration\").map(|d| d.as_str()) {\n                    Some(\"unlimited\") | None => RecordDuration::Unlimited,\n                    Some(seconds) => {\n                        RecordDuration::Seconds(seconds.parse().expect(\"invalid duration\"))\n                    }\n                };\n                config.format = matches.get_one(\"format\").copied();\n                config.filename = matches.get_one::<String>(\"output\").cloned();\n                config.show_line_numbers = !matches.get_flag(\"nolineno\");\n                config.lineno = if matches.get_flag(\"nolineno\") {\n                    LineNo::NoLine\n                } else if matches.get_flag(\"function\") {\n                    LineNo::First\n                } else {\n                    LineNo::LastInstruction\n                };\n                config.include_thread_ids = matches.get_flag(\"threads\");\n                if matches.get_flag(\"nolineno\") && matches.get_flag(\"function\") {\n                    eprintln!(\"--function & --nolinenos can't be used together\");\n                    std::process::exit(1);\n                }\n                config.hide_progress = matches.get_flag(\"hideprogress\");","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/benfred/py-spy/blob/32080cc0c22bc23938541dfa7dabb6090e40be14/src/config.rs#L377-L413","documentation":"This panic comes from parsing the --duration CLI option for the `record` subcommand. py-spy accepts \"unlimited\" or a number of seconds; any other value is parsed with u64::from_str and the failed parse panics with \"invalid duration\" via expect().","triggerScenarios":"Running `py-spy record --duration <value>` where value is neither \"unlimited\" nor omitted and does not parse as an unsigned integer (e.g. \"30s\", \"1m\", \"0.5\", \"ten\").","commonSituations":"Users pass human-friendly durations like \"--duration 5m\" or \"--duration 30s\" out of habit from tools like timeout or fluentd; or wrap the number in quotes/units by mistake in scripts.","solutions":["Pass the duration as plain seconds: `py-spy record --duration 300` instead of `--duration 5m`.","Use `--duration unlimited` (or omit --duration) for open-ended recording, and stop the process with Ctrl-C to write the output.","Convert minutes/hours to seconds in your wrapper script before invoking py-spy.","Patch config.rs to parse duration suffixes if you build py-spy from source."],"exampleFix":"// before\npy-spy record --duration 5m -o profile.svg --pid 1234\n// after\npy-spy record --duration 300 -o profile.svg --pid 1234","handlingStrategy":"validation","validationCode":"case \"$DURATION\" in\n  unlimited|'') ;;\n  *[!0-9]*|[!0-9]*) echo \"--duration must be 'unlimited' or plain seconds\" >&2; exit 1 ;;\nesac","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --duration as a bare integer number of seconds.","Use 'unlimited' (or omit the flag) for open-ended recordings.","Convert units (m/h) to seconds in wrapper scripts before invoking py-spy."],"tags":["cli","argument-parsing","panic","duration"],"backgroundTag":"invalid-duration-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"}