{"record":{"id":"6e22703a4af6f07c","repo":"databendlabs/databend","slug":"failed-to-parse-string-port-to-u16","errorCode":null,"errorMessage":"Failed to parse String port to u16","messagePattern":"Failed to parse String port to u16","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/sql/src/planner/semantic/type_check/adapter.rs","lineNumber":243,"sourceCode":"                DictionarySource::Mysql(SqlSource {\n                    connection_url,\n                    table: table.to_string(),\n                    key_field: primary_field.name.clone(),\n                    value_field: attr_field.name.clone(),\n                })\n            }\n            \"redis\" => {\n                let host = dictionary\n                    .options\n                    .get(\"host\")\n                    .ok_or_else(|| ErrorCode::BadArguments(\"Miss option `host`\"))?;\n                let port_str = dictionary\n                    .options\n                    .get(\"port\")\n                    .ok_or_else(|| ErrorCode::BadArguments(\"Miss option `port`\"))?;\n                let port = port_str\n                    .parse()\n                    .expect(\"Failed to parse String port to u16\");\n                let username = dictionary.options.get(\"username\").cloned();\n                let password = dictionary.options.get(\"password\").cloned();\n                let db_index = dictionary\n                    .options\n                    .get(\"db_index\")\n                    .map(|i| i.parse::<i64>().unwrap());\n                DictionarySource::Redis(RedisSource {\n                    host: host.to_string(),\n                    port,\n                    username,\n                    password,\n                    db_index,\n                })\n            }\n            _ => {\n                return Err(ErrorCode::Unimplemented(format!(\n                    \"Unsupported source {}\",\n                    dictionary.source","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/sql/src/planner/semantic/type_check/adapter.rs#L225-L261","documentation":"This panic occurs while resolving a dictionary definition: the `port` option is parsed as a u16 with expect. If the user supplies a non-numeric or out-of-range port value, parse() fails and the planner panics instead of returning a clean error.","triggerScenarios":"Creating or querying a dictionary (e.g. CREATE DICTIONARY ... SOURCE(REDIS/MYSQL ...)) where the `port` option string is not a valid u16 — empty string, non-numeric text, a negative number, or a value above 65535.","commonSituations":"Typo in the port value in DDL, quoting mistakes putting extra characters into the port option, copying a URL or service name into the port field, or a template variable expanding to an empty value.","solutions":["Supply a valid numeric port between 0 and 65535 in the dictionary `port` option.","Check the DDL for stray characters or quotes inside the port option value.","Replace the expect with ErrorCode::BadArguments to fail gracefully (code-level fix)."],"exampleFix":"-- before\nCREATE DICTIONARY d (...) SOURCE(REDIS HOST '127.0.0.1' PORT 'redis' ...);\n-- after\nCREATE DICTIONARY d (...) SOURCE(REDIS HOST '127.0.0.1' PORT 6379 ...);","handlingStrategy":"validation","validationCode":"// validate the dictionary port before DDL\nfn valid_port(p: &str) -> bool {\n    p.parse::<u16>().map(|v| v > 0).unwrap_or(false)\n}\nassert!(valid_port(\"6379\"), \"dictionary option 'port' must be a u16 in 1..=65535\");","typeGuard":null,"tryCatchPattern":"// recommended code-level fix: replace expect with a typed error\nlet port: u16 = port_str.parse().map_err(|_|\n    ErrorCode::BadArguments(format!(\"option `port` is not a valid u16: {}\", port_str)))?;","preventionTips":["Always quote/validate the port value in CREATE DICTIONARY DDL.","Check templates/variables when ports come from config interpolation.","Keep port in 1..=65535; Redis/MySQL defaults are 6379/3306.","Replace parse().expect with map_err(BadArguments) when editing this code path."],"tags":["rust","panic","dictionary","port","configuration"],"backgroundTag":"invalid-argument-value","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}