databendlabs/databend · error

Failed to parse String port to u16

Error message

Failed to parse String port to u16

What it means

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.

Solutions

  1. Supply a valid numeric port between 0 and 65535 in the dictionary `port` option.
  2. Check the DDL for stray characters or quotes inside the port option value.
  3. Replace the expect with ErrorCode::BadArguments to fail gracefully (code-level fix).

Example fix

-- before
CREATE DICTIONARY d (...) SOURCE(REDIS HOST '127.0.0.1' PORT 'redis' ...);
-- after
CREATE DICTIONARY d (...) SOURCE(REDIS HOST '127.0.0.1' PORT 6379 ...);
Defensive patterns

Strategy: validation

Validate before calling

// validate the dictionary port before DDL
fn valid_port(p: &str) -> bool {
    p.parse::<u16>().map(|v| v > 0).unwrap_or(false)
}
assert!(valid_port("6379"), "dictionary option 'port' must be a u16 in 1..=65535");

Try / catch

// recommended code-level fix: replace expect with a typed error
let port: u16 = port_str.parse().map_err(|_|
    ErrorCode::BadArguments(format!("option `port` is not a valid u16: {}", port_str)))?;

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of databendlabs/databend@288d84d76e (2026-09-11). Data as JSON: /api/errors/6e22703a4af6f07c. Report an issue: GitHub.

Appendix: source

Thrown at src/query/sql/src/planner/semantic/type_check/adapter.rs:243

                DictionarySource::Mysql(SqlSource {
                    connection_url,
                    table: table.to_string(),
                    key_field: primary_field.name.clone(),
                    value_field: attr_field.name.clone(),
                })
            }
            "redis" => {
                let host = dictionary
                    .options
                    .get("host")
                    .ok_or_else(|| ErrorCode::BadArguments("Miss option `host`"))?;
                let port_str = dictionary
                    .options
                    .get("port")
                    .ok_or_else(|| ErrorCode::BadArguments("Miss option `port`"))?;
                let port = port_str
                    .parse()
                    .expect("Failed to parse String port to u16");
                let username = dictionary.options.get("username").cloned();
                let password = dictionary.options.get("password").cloned();
                let db_index = dictionary
                    .options
                    .get("db_index")
                    .map(|i| i.parse::<i64>().unwrap());
                DictionarySource::Redis(RedisSource {
                    host: host.to_string(),
                    port,
                    username,
                    password,
                    db_index,
                })
            }
            _ => {
                return Err(ErrorCode::Unimplemented(format!(
                    "Unsupported source {}",
                    dictionary.source

View on GitHub (pinned to 288d84d76e)