{"record":{"id":"d93e9668ff28a495","repo":"t8y2/dbx","slug":"invalid-cassandra-port-s","errorCode":null,"errorMessage":"invalid Cassandra port: %s","messagePattern":"invalid Cassandra port: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/cassandra-go/config.go","lineNumber":134,"sourceCode":"\t}\n\tparsed, err := url.Parse(value)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid Cassandra connection string: %w\", err)\n\t}\n\tif parsed.Scheme != \"cassandra\" {\n\t\treturn fmt.Errorf(\"unsupported Cassandra connection scheme: %s\", parsed.Scheme)\n\t}\n\tif parsed.User != nil {\n\t\tconfig.username = parsed.User.Username()\n\t\tif password, ok := parsed.User.Password(); ok {\n\t\t\tconfig.password = password\n\t\t}\n\t}\n\tconfig.hosts = splitHosts(parsed.Host)\n\tif port := parsed.Port(); port != \"\" {\n\t\tparsedPort, parseErr := strconv.Atoi(port)\n\t\tif parseErr != nil || parsedPort < 1 || parsedPort > 65535 {\n\t\t\treturn fmt.Errorf(\"invalid Cassandra port: %s\", port)\n\t\t}\n\t\tconfig.port = parsedPort\n\t}\n\tif keyspace := strings.Trim(strings.TrimSpace(parsed.Path), \"/\"); keyspace != \"\" {\n\t\tconfig.keyspace = keyspace\n\t}\n\tfor key, values := range parsed.Query() {\n\t\tparams[key] = values\n\t}\n\treturn nil\n}\n\nfunc parseURLParams(raw string) (url.Values, error) {\n\traw = strings.TrimPrefix(strings.TrimSpace(raw), \"?\")\n\tif raw == \"\" {\n\t\treturn url.Values{}, nil\n\t}\n\tvalues, err := url.ParseQuery(raw)","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/cassandra-go/config.go#L116-L152","documentation":"applyConnectionString validates the port parsed from the URL host and returns \"invalid Cassandra port: %s\" when strconv.Atoi fails or the number is outside 1–65535. The port must be a valid TCP port for the driver to configure the CQL connection.","triggerScenarios":"Connection strings like \"cassandra://host:9042x\", \"cassandra://host:0\", \"cassandra://host:70000\", or \"cassandra://host:\" where the Port() substring is non-empty but not a number in range.","commonSituations":"Typo appending a character to the port; using 0 as a placeholder; copy-pasting a multi-port value (9042,9142) into the port slot; confusing the CQL port (9042) with the thrift/storage ports (9160/7000).","solutions":["Use a valid numeric port 1–65535, typically 9042 for CQL.","Remove trailing characters or extra values after the port.","Omit the port entirely to use the driver default.","Pre-validate with strconv.Atoi and range-check before building the URL."],"exampleFix":"// before\ndriver.Open(\"cassandra://10.0.0.5:9042,9142/sales\")\n// after\ndriver.Open(\"cassandra://10.0.0.5:9042/sales\")","handlingStrategy":"validation","validationCode":"if u, err := url.Parse(strings.TrimPrefix(dsn, \"jdbc:\")); err == nil {\n    if p := u.Port(); p != \"\" {\n        n, e := strconv.Atoi(p)\n        if e != nil || n < 1 || n > 65535 {\n            return fmt.Errorf(\"port %q out of range 1-65535\", p)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"conn, err := driver.Open(dsn)\nif err != nil && strings.Contains(err.Error(), \"invalid Cassandra port\") {\n    return nil, fmt.Errorf(\"use a numeric TCP port 1-65535 (CQL default 9042): %w\", err)\n}","preventionTips":["Default to port 9042 for CQL and omit it from the DSN when standard.","Never place comma-separated multi-port values in the port slot; list hosts separately.","Range-check ports with strconv.Atoi when building DSNs from user input.","Do not confuse CQL port 9042 with thrift (9160) or storage (7000) ports."],"tags":["configuration","cassandra","port","validation"],"backgroundTag":"invalid-port-number","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}