{"record":{"id":"88812dfdec27fc8b","repo":"tinyhumansai/openhuman","slug":"invalid-port-e","errorCode":null,"errorMessage":"invalid --port: {e}","messagePattern":"invalid --port: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/core/cli.rs","lineNumber":377,"sourceCode":"fn run_server_command(args: &[String]) -> Result<()> {\n    let mut port: Option<u16> = None;\n    let mut host: Option<String> = None;\n    let mut socketio_enabled = true;\n    let mut headless_api = false;\n    let mut verbose = false;\n    let log_scope = CliLogDefault::Global;\n    let mut i = 0usize;\n\n    // Manual argument parsing loop for specific flags.\n    while i < args.len() {\n        match args[i].as_str() {\n            \"--port\" => {\n                let raw = args\n                    .get(i + 1)\n                    .ok_or_else(|| anyhow::anyhow!(\"missing value for --port\"))?;\n                port = Some(\n                    raw.parse::<u16>()\n                        .map_err(|e| anyhow::anyhow!(\"invalid --port: {e}\"))?,\n                );\n                i += 2;\n            }\n            \"--host\" => {\n                host = Some(\n                    args.get(i + 1)\n                        .ok_or_else(|| anyhow::anyhow!(\"missing value for --host\"))?\n                        .clone(),\n                );\n                i += 2;\n            }\n            \"--jsonrpc-only\" => {\n                socketio_enabled = false;\n                i += 1;\n            }\n            \"--headless-api\" => {\n                socketio_enabled = false;\n                headless_api = true;","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/a221052e0df5b1f7598fceba7329fd1af95d6699/src/core/cli.rs#L359-L395","documentation":"The token after `--port` failed to parse as u16. Because this parser consumes the next token unconditionally, the failure covers three shapes: non-numeric text, a number outside 0–65535, and a swallowed flag (`--port --host x` makes '--host' the value). An empty quoted value ('') also parses to nothing and lands here.","triggerScenarios":"`--port abc`; `--port 70000` (above u16 range); `--port --host 0.0.0.0` (flag consumed as value); `--port \"\"` from an unset env variable expansion.","commonSituations":"`--port \"$PORT\"` with PORT unset or non-numeric; forwarding a container/CI port variable with a different range convention; placeholder text like `<port>` left in the command.","solutions":["Use an integer in 0–65535: `openhuman run --port 7788`","Validate/normalize the variable before use: `PORT=${PORT:-7788}` and check it is numeric","Omit the flag to fall back to the default 7788 or OPENHUMAN_CORE_PORT"],"exampleFix":"# before (PORT unset -> empty string)\nopenhuman run --port \"$PORT\"\n# after\nPORT=\"${PORT:-7788}\"\nopenhuman run --port \"$PORT\"","handlingStrategy":"validation","validationCode":"# bash: validate u16 shape and range before passing it on\nPORT=\"${PORT:-7788}\"\nif ! [[ \"$PORT\" =~ ^[0-9]+$ ]] || (( PORT < 0 || PORT > 65535 )); then\n  echo \"invalid port: $PORT (expected 0-65535)\" >&2; exit 2\nfi\nopenhuman run --port \"$PORT\"","typeGuard":"// Rust wrapper: narrow to u16 before formatting the CLI arg\nfn valid_port(s: &str) -> Option<u16> { s.trim().parse::<u16>().ok() }","tryCatchPattern":null,"preventionTips":["Never pass a flag-looking token after --port — it gets consumed as the value and fails the u16 parse","Default empty variables: PORT=${PORT:-7788} before interpolation","Remember the valid range is exactly 0–65535 (u16); 70000 fails"],"tags":["cli","argument-parsing","validation","server"],"backgroundTag":null,"analyzedSha":"a221052e0df5b1f7598fceba7329fd1af95d6699","analyzedAt":"2026-08-16T12:47:06.542Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}