vitessio/vitess · error
failed to convert %s: %v
Error message
failed to convert %s: %v
What it means
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.
Source
Thrown at go/vt/mysqlctl/mycnf.go:150
func (cnf *Mycnf) lookupWithDefault(key, defaultVal string) (string, error) {
val := cnf.lookup(key)
if val == "" {
if defaultVal == "" {
return "", fmt.Errorf("value for key '%v' not set and no default value set", key)
}
return defaultVal, nil
}
return val, nil
}
func (cnf *Mycnf) lookupInt(key string) (int, error) {
val, err := cnf.lookupWithDefault(key, "")
if err != nil {
return 0, err
}
ival, err := strconv.Atoi(val)
if err != nil {
return 0, fmt.Errorf("failed to convert %s: %v", key, err)
}
return ival, nil
}
func normKey(bkey []byte) string {
// FIXME(msolomon) People are careless about hyphen vs underscore - we should normalize.
// But you have to normalize to hyphen, or mysqld_safe can fail.
return string(bytes.ReplaceAll(bytes.TrimSpace(bkey), []byte("_"), []byte("-")))
}
// ReadMycnf will read an existing my.cnf from disk, and update the passed in Mycnf object
// with values from the my.cnf on disk.
func ReadMycnf(mycnf *Mycnf, waitTime time.Duration) (*Mycnf, error) {
f, err := os.Open(mycnf.Path)
if waitTime != 0 {
timer := time.NewTimer(waitTime)
for err != nil {
select {View on GitHub (pinned to 01a25a7d17)
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.
Example fix
// before port = "3306" ; primary port // after port = 3306
Defensive patterns
Strategy: validation
Validate before calling
for _, line := range strings.Split(string(data), "\n") {
if k, v, ok := parseCnfLine(line); ok && k == "port" {
if _, err := strconv.Atoi(strings.TrimSpace(v)); err != nil {
return fmt.Errorf("mycnf port not numeric: %q", v)
}
}
} Try / catch
val, err := mycnf.lookupInt("port")
if err != nil {
return fmt.Errorf("bad my.cnf integer: %w", err)
} Prevention
- 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
When it happens
Trigger: ReadMycnf calling lookupInt (e.g. for 'port') when the config value contains non-numeric characters, units ('3306M'), quotes, comments, or stray whitespace.
Common situations: Hand-edited my.cnf with values like port = 3306; # comment on same line; variables like port = ${PORT} left unexpanded; corruption from a provisioning tool.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- cannot perform backup without my.cnf, please restart vttable
- invalid FilterByShard parameter: %v
- error parsing shard name %v: %v
- duplicate %v/%v entry
- value for key '%v' not set and no default value set
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/b1195ed74f60495d.
Report an issue: GitHub.