{"record":{"id":"8418ef11b81c9c81","repo":"vitessio/vitess","slug":"value-for-key-v-not-set-and-no-default-value-se","errorCode":null,"errorMessage":"value for key '%v' not set and no default value set","messagePattern":"value for key '(.+?)' not set and no default value set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/mycnf.go","lineNumber":136,"sourceCode":"const (\n\tmyCnfWaitRetryTime = 100 * time.Millisecond\n)\n\n// TabletDir returns the tablet directory.\nfunc (cnf *Mycnf) TabletDir() string {\n\treturn path.Dir(cnf.DataDir)\n}\n\nfunc (cnf *Mycnf) lookup(key string) string {\n\tkey = normKey([]byte(key))\n\treturn cnf.mycnfMap[key]\n}\n\nfunc (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","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/mycnf.go#L118-L154","documentation":"Mycnf.lookupWithDefault is the accessor for my.cnf values; when the key is absent (or empty) AND the provided defaultVal is also empty, no value can be resolved and this error is returned. ReadMycnf uses it to enforce that mandatory settings like server-id exist.","triggerScenarios":"lookupInt or ReadMycnf calls lookupWithDefault for a key that is missing from the parsed my.cnf and passes \"\" as the default — e.g. missing server-id, datadir, or socket entries.","commonSituations":"my.cnf missing required sections because MySQL was initialized differently; extra_mycnf_values not providing the key; parsing a config file written for a different MySQL flavor with different option names.","solutions":["Ensure my.cnf contains the missing key (e.g. server-id) under the expected section.","Supply the value via extra_mycnf_values / MycnfFile overrides.","If a sane fallback exists, pass it as defaultVal instead of \"\" in the calling code."],"exampleFix":"// before\nserverIDStr, err := mycnf.lookupWithDefault(\"server-id\", \"\")\n// after (config side)\n# my.cnf\n[mysqld]\nserver-id = 1234","handlingStrategy":"validation","validationCode":"// before creating Mycnf from a file, ensure required keys exist\ndata, _ := os.ReadFile(mycnfPath)\nfor _, key := range []string{\"server-id\", \"datadir\", \"innodb-log-file-size\"} {\n\tif !bytes.Contains(data, []byte(key)) { return fmt.Errorf(\"mycnf missing %s\", key) }\n}","typeGuard":null,"tryCatchPattern":"port, err := mycnf.lookupInt(\"port\")\nif err != nil {\n\treturn fmt.Errorf(\"incomplete my.cnf %s: %w\", path, err)\n}","preventionTips":["Generate my.cnf from a template that includes all mandatory keys","Validate extra_mycnf_values covers keys missing from base config","Test with the exact MySQL flavor's config format before deploy"],"tags":["mycnf","configuration","mysqlctl"],"backgroundTag":"missing-config-key","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}