{"record":{"id":"6d820ac5639806df","repo":"hashicorp/consul","slug":"invalid-type-t","errorCode":null,"errorMessage":"invalid type: %T","messagePattern":"invalid type: %T","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ipaddr/ipaddr.go","lineNumber":60,"sourceCode":"\tcase string:\n\t\treturn x\n\tcase *string:\n\t\tif x == nil {\n\t\t\treturn \"\"\n\t\t}\n\t\treturn *x\n\tcase net.IP:\n\t\treturn x.String()\n\tcase *net.IP:\n\t\treturn x.String()\n\tcase *net.IPAddr:\n\t\treturn x.IP.String()\n\tcase *net.TCPAddr:\n\t\treturn x.IP.String()\n\tcase *net.UDPAddr:\n\t\treturn x.IP.String()\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"invalid type: %T\", ip))\n\t}\n}\n","sourceCodeStart":42,"sourceCodeEnd":63,"githubUrl":"https://github.com/hashicorp/consul/blob/2397ff0d763d34f2fe37fe59fde6a7f7fc430a3e/ipaddr/ipaddr.go#L42-L63","documentation":"The unexported iptos helper in ipaddr/ipaddr.go:60 panics for any type outside its type switch: string, *string, net.IP, *net.IP, *net.IPAddr, *net.TCPAddr, *net.UDPAddr. It backs the public helpers IsAny, IsAnyV4 and IsAnyV6, which accept interface{} precisely so several address representations can be passed. Note the asymmetry: net.IP is accepted by value, but IPAddr/TCPAddr/UDPAddr are only accepted as pointers, and net.IPNet or custom Stringer types are not accepted at all.","triggerScenarios":"Calling ipaddr.IsAny with a value (non-pointer) net.TCPAddr or net.UDPAddr; passing a net.IPNet (e.g. from parsing a CIDR); passing a custom type that merely implements fmt.Stringer; passing *net.TCPListener or other socket types.","commonSituations":"Refactoring address plumbing so a value that used to be *net.TCPAddr is now passed by value; feeding a subnet (net.IPNet) instead of its .IP field; assuming any Stringer works because the parameter is interface{}.","solutions":["Convert before calling: pass ip.String() (string) or the net.IP field of the struct you hold","Use the pointer form: pass &tcpAddr, not tcpAddr","For net.IPNet, pass only its .IP field","If a type is broadly needed, extend iptos with a new case (contribute upstream)"],"exampleFix":"// before\naddr := net.TCPAddr{IP: net.ParseIP(\"0.0.0.0\")}\nipaddr.IsAny(addr) // value net.TCPAddr not in switch -> panics\n\n// after\nipaddr.IsAny(&addr) // *net.TCPAddr is supported\n// or\nipaddr.IsAny(\"0.0.0.0\") // plain string is supported","handlingStrategy":"type-guard","validationCode":"func toAddrString(v any) (string, bool) {\n\tswitch x := v.(type) {\n\tcase string:\n\t\treturn x, true\n\tcase *string:\n\t\tif x == nil {\n\t\t\treturn \"\", true\n\t\t}\n\t\treturn *x, true\n\tcase net.IP:\n\t\treturn x.String(), true\n\tcase *net.IP:\n\t\treturn x.String(), true\n\tcase *net.IPAddr:\n\t\treturn x.IP.String(), true\n\tcase *net.TCPAddr:\n\t\treturn x.IP.String(), true\n\tcase *net.UDPAddr:\n\t\treturn x.IP.String(), true\n\t}\n\treturn \"\", false\n}\n\nif s, ok := toAddrString(addr); ok {\n\t_ = ipaddr.IsAny(s)\n}","typeGuard":"func supportedAddrType(v any) bool {\n\tswitch v.(type) {\n\tcase string, *string, net.IP, *net.IP, *net.IPAddr, *net.TCPAddr, *net.UDPAddr:\n\t\treturn true\n\t}\n\treturn false\n}","tryCatchPattern":"func safeIsAny(v any) (b bool, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"ipaddr: unsupported address type: %v\", r)\n\t\t}\n\t}()\n\treturn ipaddr.IsAny(v), nil\n}","preventionTips":["Prefer passing a plain string or net.IP into ipaddr helpers; both are always in the switch","Watch the value/pointer asymmetry: TCPAddr/UDPAddr/IPAddr must be pointers, net.IP must be a value","For net.IPNet pass .IP; for custom Stringer types call .String() yourself"],"tags":["go","consul","panic","type-switch","networking","net","ip-address"],"backgroundTag":null,"analyzedSha":"2397ff0d763d34f2fe37fe59fde6a7f7fc430a3e","analyzedAt":"2026-08-15T19:19:47.700Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}