{"record":{"id":"ac08d07dedf7e336","repo":"vitessio/vitess","slug":"bad-command-line-format-for-zk-config","errorCode":null,"errorMessage":"bad command line format for zk config","messagePattern":"bad command line format for zk config","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/zkctl/zkconf.go","lineNumber":150,"sourceCode":"\treturn cnfData.String(), nil\n}\n\nconst GuessMyID = 0\n\n/*\nCreate a config for this instance.\n\n<server_id>@<hostname>:<leader_port>:<election_port>:<client_port>\n\nIf server_id > 1000, then we assume this is a global quorum.\nserver_id's must be 1-255, global id's are 1001-1255 mod 1000.\n*/\nfunc MakeZkConfigFromString(cmdLine string, myID uint32) *ZkConfig {\n\tzkConfig := NewZkConfig()\n\tfor zki := range strings.SplitSeq(cmdLine, \",\") {\n\t\tzkiParts := strings.SplitN(zki, \"@\", 2)\n\t\tif len(zkiParts) != 2 {\n\t\t\tpanic(\"bad command line format for zk config\")\n\t\t}\n\t\tzkID := zkiParts[0]\n\t\tzkAddrParts := strings.Split(zkiParts[1], \":\")\n\t\tserverID, _ := strconv.ParseUint(zkID, 10, 32)\n\t\tif serverID > 1000 {\n\t\t\tserverID = serverID % 1000\n\t\t\tzkConfig.Global = true\n\t\t}\n\t\tmyID = myID % 1000\n\n\t\tzkServer := zkServerAddr{\n\t\t\tServerId: uint32(serverID), ClientPort: 2181,\n\t\t\tLeaderPort: 2888, ElectionPort: 3888,\n\t\t}\n\t\tswitch len(zkAddrParts) {\n\t\tcase 4:\n\t\t\tzkServer.ClientPort, _ = strconv.Atoi(zkAddrParts[3])\n\t\t\tfallthrough","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/zkctl/zkconf.go#L132-L168","documentation":"MakeZkConfigFromString panics with 'bad command line format for zk config' when the comma-separated zk server string contains an entry without the required 'serverID@host:port' format — specifically when splitting an entry on '@' does not yield exactly 2 parts. The function converts the CLI string into a ZkConfig for starting/using ZooKeeper.","triggerScenarios":"Calling MakeZkConfigFromString with an entry missing '@', e.g. '1@host:2181,host2:2181' or an empty entry from a trailing comma '1@h:2181,'.","commonSituations":"Typo in vtctld/vttablet -zk_server args (missing @); copy-pasting a host list without server IDs; stray or leading/trailing commas; forgetting the numeric server ID prefix.","solutions":["Fix the command line so each comma-separated entry is 'serverID@host:port', e.g. '1@zk1:2181,2@zk2:2181,3@zk3:2181'.","Remove empty entries / stray commas from the string.","Verify the flag value with the exact documented format before launch (count of '@' equals number of entries)."],"exampleFix":"// before\nMakeZkConfigFromString(\"zk1:2181,zk2:2181\", myID)\n// after\nMakeZkConfigFromString(\"1@zk1:2181,2@zk2:2181\", myID)","handlingStrategy":"validation","validationCode":"func validZkArg(s string) bool {\n    for _, part := range strings.Split(s, \",\") {\n        if strings.Count(part, \"@\") != 1 || part == \"\" {\n            return false\n        }\n    }\n    return true\n}\nif !validZkArg(cmdLine) {\n    return errors.New(\"zk config must be serverID@host:port,serverID@host:port\")\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        if r == \"bad command line format for zk config\" {\n            log.Fatalf(\"invalid -zk argument; expected serverID@host:port entries\")\n            return\n        }\n        panic(r)\n    }\n}()","preventionTips":["Validate the -zk flag format at startup before calling MakeZkConfigFromString","Use flag help/examples showing '1@host:2181,2@host:2181'","Trim and check for empty comma-separated entries","Add a unit test for malformed zk config strings"],"tags":["zookeeper","zkctl","config-parsing","command-line"],"backgroundTag":"zk-config-format-error","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}