{"record":{"id":"7a102de4f8d54d62","repo":"ipfs/kubo","slug":"unknown-autonat-mode-s","errorCode":null,"errorMessage":"unknown autonat mode: %s","messagePattern":"unknown autonat mode: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/autonat.go","lineNumber":39,"sourceCode":"\t// AutoNATService.\n\tAutoNATServiceDisabled\n\t// AutoNATServiceEnabledV1Only forces use of V1 and disables V2\n\t// (used for testing)\n\tAutoNATServiceEnabledV1Only\n)\n\nfunc (m *AutoNATServiceMode) UnmarshalText(text []byte) error {\n\tswitch string(text) {\n\tcase \"\":\n\t\t*m = AutoNATServiceUnset\n\tcase \"enabled\":\n\t\t*m = AutoNATServiceEnabled\n\tcase \"disabled\":\n\t\t*m = AutoNATServiceDisabled\n\tcase \"legacy-v1\":\n\t\t*m = AutoNATServiceEnabledV1Only\n\tdefault:\n\t\treturn fmt.Errorf(\"unknown autonat mode: %s\", string(text))\n\t}\n\treturn nil\n}\n\nfunc (m AutoNATServiceMode) MarshalText() ([]byte, error) {\n\tswitch m {\n\tcase AutoNATServiceUnset:\n\t\treturn nil, nil\n\tcase AutoNATServiceEnabled:\n\t\treturn []byte(\"enabled\"), nil\n\tcase AutoNATServiceDisabled:\n\t\treturn []byte(\"disabled\"), nil\n\tcase AutoNATServiceEnabledV1Only:\n\t\treturn []byte(\"legacy-v1\"), nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unknown autonat mode: %d\", m)\n\t}\n}","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/config/autonat.go#L21-L57","documentation":"AutoNATServiceMode.UnmarshalText parses the AutoNAT.Mode config string into the typed enum. It accepts 'enabled', 'disabled', and 'legacy-v1'; any other string hits the default branch and returns 'unknown autonat mode: %s'. This is a strict config-schema validation error at config load time.","triggerScenarios":"Setting AutoNAT.Mode in the kubo config (or via ipfs config AutoNAT.Mode X) to a value outside {enabled, disabled, legacy-v1}, e.g. 'enable', 'auto', 'true', or an older removed mode name.","commonSituations":"Config copied from documentation of a different version where a mode name changed; typo when hand-editing config.json; migration scripts writing boolean-like values ('on'/'off') instead of enum strings.","solutions":["Set AutoNAT.Mode to one of: enabled, disabled, legacy-v1 (ipfs config AutoNAT.Mode enabled)","Check the exact spelling/case against the current version's docs/config.md","If migrating from an old mode name, map it: 'enabled' for default service, 'legacy-v1' for v1-only behavior, 'disabled' to turn it off"],"exampleFix":"// before (config.json)\n\"AutoNAT\": { \"Mode\": \"on\" }\n// after\n\"AutoNAT\": { \"Mode\": \"enabled\" }","handlingStrategy":"validation","validationCode":"var mode config.AutoNATServiceMode\nif err := mode.UnmarshalText([]byte(cfgValue)); err != nil {\n    return fmt.Errorf(\"bad AutoNAT.Mode %q: valid values are enabled, disabled, legacy-v1\", cfgValue)\n}","typeGuard":"func validAutoNATMode(s string) bool {\n    switch s { case \"enabled\", \"disabled\", \"legacy-v1\": return true }\n    return false\n}","tryCatchPattern":"if err := json.Unmarshal(rawCfg, &cfg); err != nil {\n    var ue *json.UnmarshalTypeError\n    if errors.As(err, &ue) && strings.Contains(ue.Error(), \"autonat\") { fixAutoNATMode() }\n    return err\n}","preventionTips":["Only set AutoNAT.Mode via `ipfs config AutoNAT.Mode <value>` so the CLI validates the enum","Whitelist allowed values in automation scripts before writing config.json","Re-check mode names when upgrading kubo versions; enum members can change"],"tags":["config","autonat","unmarshal","enum-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}