{"record":{"id":"b1195ed74f60495d","repo":"vitessio/vitess","slug":"failed-to-convert-s-v","errorCode":null,"errorMessage":"failed to convert %s: %v","messagePattern":"failed to convert (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/mycnf.go","lineNumber":150,"sourceCode":"func (cnf *Mycnf) lookupWithDefault(key, defaultVal string) (string, error) {\n\tval := cnf.lookup(key)\n\tif val == \"\" {\n\t\tif defaultVal == \"\" {\n\t\t\treturn \"\", fmt.Errorf(\"value for key '%v' not set and no default value set\", key)\n\t\t}\n\t\treturn defaultVal, nil\n\t}\n\treturn val, nil\n}\n\nfunc (cnf *Mycnf) lookupInt(key string) (int, error) {\n\tval, err := cnf.lookupWithDefault(key, \"\")\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tival, err := strconv.Atoi(val)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to convert %s: %v\", key, err)\n\t}\n\treturn ival, nil\n}\n\nfunc normKey(bkey []byte) string {\n\t// FIXME(msolomon) People are careless about hyphen vs underscore - we should normalize.\n\t// But you have to normalize to hyphen, or mysqld_safe can fail.\n\treturn string(bytes.ReplaceAll(bytes.TrimSpace(bkey), []byte(\"_\"), []byte(\"-\")))\n}\n\n// ReadMycnf will read an existing my.cnf from disk, and update the passed in Mycnf object\n// with values from the my.cnf on disk.\nfunc ReadMycnf(mycnf *Mycnf, waitTime time.Duration) (*Mycnf, error) {\n\tf, err := os.Open(mycnf.Path)\n\tif waitTime != 0 {\n\t\ttimer := time.NewTimer(waitTime)\n\t\tfor err != nil {\n\t\t\tselect {","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/mycnf.go#L132-L168","documentation":"lookupInt fetches a my.cnf key via lookupWithDefault then strconv.Atoi's the string; if the value is present but not a valid integer, this error wraps the key name and Atoi error. It means the my.cnf holds a non-numeric value where an integer was expected.","triggerScenarios":"ReadMycnf calling lookupInt (e.g. for 'port') when the config value contains non-numeric characters, units ('3306M'), quotes, comments, or stray whitespace.","commonSituations":"Hand-edited my.cnf with values like port = 3306; # comment on same line; variables like port = ${PORT} left unexpanded; corruption from a provisioning tool.","solutions":["Fix the my.cnf entry to contain a plain integer (e.g. port = 3306).","Remove quotes, units, inline comments, or whitespace from the value.","Check provisioning scripts/template rendering for unexpanded variables."],"exampleFix":"// before\nport = \"3306\" ; primary port\n// after\nport = 3306","handlingStrategy":"validation","validationCode":"for _, line := range strings.Split(string(data), \"\\n\") {\n\tif k, v, ok := parseCnfLine(line); ok && k == \"port\" {\n\t\tif _, err := strconv.Atoi(strings.TrimSpace(v)); err != nil {\n\t\t\treturn fmt.Errorf(\"mycnf port not numeric: %q\", v)\n\t\t}\n\t}\n}","typeGuard":null,"tryCatchPattern":"val, err := mycnf.lookupInt(\"port\")\nif err != nil {\n\treturn fmt.Errorf(\"bad my.cnf integer: %w\", err)\n}","preventionTips":["Keep my.cnf free of inline comments, quotes, and units on numeric options","Verify template rendering substitutes all variables","Add a config linter step in provisioning that Atoi-checks numeric fields"],"tags":["mycnf","configuration","parsing"],"backgroundTag":"invalid-config-value","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}