{"record":{"id":"521ce3eb98cc99e8","repo":"OpenNHP/opennhp","slug":"unsupported-type-t","errorCode":null,"errorMessage":"unsupported type: %T","messagePattern":"unsupported type: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nhp/utils/utils.go","lineNumber":165,"sourceCode":"\t}\n\n\treturn data, nil\n}\n\nfunc UpdateTomlConfig(filePath string, key string, value any) error {\n\tcontent, err := os.ReadFile(filePath)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar newContent string\n\n\tswitch value := value.(type) {\n\tcase string:\n\t\tre := regexp.MustCompile(`(?m)^\\s*` + key + `\\s*=\\s*\".+\"\\s*$`)\n\t\tnewContent = re.ReplaceAllString(string(content), fmt.Sprintf(\"%s = \\\"%s\\\"\", key, value))\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported type: %T\", value)\n\t}\n\n\terr = os.WriteFile(filePath, []byte(newContent), 0644) //nolint:gosec // G306: Config files are typically world-readable\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":147,"sourceCodeEnd":175,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/nhp/utils/utils.go#L147-L175","documentation":"UpdateTomlConfig performs regex-based replacement of a `key = \"...\"` line in a TOML file, but its type switch only supports string values. Any non-string value (int, bool, float, slice) hits the default branch and returns this error naming the actual Go type (%T). It is a capability limitation of this utility, not a file problem.","triggerScenarios":"Calling UpdateTomlConfig(path, key, 42), (path, key, true), or any non-string value - e.g. RotateTeeKey/RotateAgentKey style code passing a numeric port or boolean flag to update in a TOML config.","commonSituations":"Trying to update `port = 8080` or `enabled = true` entries in config.toml; refactored code where the value type changed from string to int after a config schema change; passing values read back from JSON unmarshalling, where numbers arrive as float64.","solutions":["Pass the value as a string, e.g. strconv.Itoa(port) or strconv.FormatBool(enabled), since only string is supported.","Extend UpdateTomlConfig with cases for other types (int, bool, float64) or use a real TOML library such as github.com/pelletier/go-toml/v2 to set the value.","Note the regex only matches quoted values anyway (`\".+\"`), so unquoted TOML values must be handled separately even for string-typed rewrites of numeric keys."],"exampleFix":"// before\nerr := utils.UpdateTomlConfig(\"etc/config.toml\", \"port\", 8080) // unsupported type: int\n// after\nerr := utils.UpdateTomlConfig(\"etc/config.toml\", \"port\", strconv.Itoa(8080))","handlingStrategy":"type-guard","validationCode":"if s, ok := value.(string); !ok {\n    return fmt.Errorf(\"UpdateTomlConfig only accepts string values; got %T\", value)\n}","typeGuard":"func isStringValue(v any) (string, bool) {\n    s, ok := v.(string)\n    return s, ok\n}","tryCatchPattern":"if err := utils.UpdateTomlConfig(path, key, value); err != nil && strings.HasPrefix(err.Error(), \"unsupported type:\") {\n    // fall back to go-toml v2 tree.Set(key, value) and write back\n}","preventionTips":["Coerce numeric/boolean values with strconv before calling.","Prefer github.com/pelletier/go-toml/v2 for typed TOML edits instead of regex replacement.","Document that this helper only rewrites quoted string values.","Add tests covering int/bool values to catch type regressions early."],"tags":["go","toml","configuration","type-mismatch"],"backgroundTag":"unsupported-operation","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}