{"record":{"id":"86e69cfc19c7b5ed","repo":"kovidgoyal/kitty","slug":"invalid-socket-address-s-must-be-prefix-by-a-pro","errorCode":null,"errorMessage":"Invalid socket address: %s must be prefix by a protocol such as unix:","messagePattern":"Invalid socket address: (.+?) must be prefix by a protocol such as unix:","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/utils/sockets.go","lineNumber":17,"sourceCode":"// License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>\n\npackage utils\n\nimport (\n\t\"fmt\"\n\t\"runtime\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/seancfoley/ipaddress-go/ipaddr\"\n)\n\nfunc ParseSocketAddress(spec string) (network string, addr string, err error) {\n\tnetwork, addr, found := strings.Cut(spec, \":\")\n\tif !found {\n\t\terr = fmt.Errorf(\"Invalid socket address: %s must be prefix by a protocol such as unix:\", spec)\n\t\treturn\n\t}\n\tif network == \"unix\" {\n\t\tif strings.HasPrefix(addr, \"@\") && runtime.GOOS != \"linux\" {\n\t\t\terr = fmt.Errorf(\"Abstract UNIX sockets are only supported on Linux. Cannot use: %s\", spec)\n\t\t}\n\t\treturn\n\t}\n\n\tif network == \"tcp\" || network == \"tcp6\" || network == \"tcp4\" {\n\t\thost := ipaddr.NewHostName(addr)\n\t\tif host.IsAddress() {\n\t\t\tnetwork = \"ip\"\n\t\t}\n\t\treturn\n\t}\n\tif network == \"ip\" || network == \"ip6\" || network == \"ip4\" {\n\t\thost := ipaddr.NewHostName(addr)","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/tools/utils/sockets.go#L1-L35","documentation":"ParseSocketAddress expects socket specs of the form network:address (e.g. unix:/path/to/sock, tcp:127.0.0.1:8080). It uses strings.Cut on the first ':'; if no colon is present the spec cannot be split into network and address and this error is returned, hinting that a protocol prefix is required.","triggerScenarios":"Passing a bare path like \"/run/app.sock\" or \"localhost:8080\" without a leading network type — note that \"localhost:8080\" would parse network=\"localhost\" and hit the unknown-network error instead; the colon-less case is things like \"app.sock\".","commonSituations":"CLI/config values for listen addresses written without the protocol prefix; porting configs from tools that accept bare paths; setup_global_options parsing --listen argument.","solutions":["Prefix the spec with a network: unix:/run/app.sock, tcp:0.0.0.0:8080, fd:3.","Update the config/CLI default and docs to the network:address form.","Validate specs with strings.Contains(spec, \":\") before startup."],"exampleFix":"// before\nnet, addr, err := utils.ParseSocketAddress(\"/run/kitty.sock\")\n// after\nnet, addr, err := utils.ParseSocketAddress(\"unix:/run/kitty.sock\")","handlingStrategy":"validation","validationCode":"if !strings.Contains(spec, \":\") {\n    return fmt.Errorf(\"socket spec %q needs a network prefix like unix:\", spec)\n}","typeGuard":"func isSocketSpec(s string) bool {\n    _, _, ok := strings.Cut(s, \":\")\n    return ok\n}","tryCatchPattern":"net, addr, err := utils.ParseSocketAddress(spec)\nif err != nil && strings.Contains(err.Error(), \"must be prefix by a protocol\") {\n    spec = \"unix:\" + spec\n    net, addr, err = utils.ParseSocketAddress(spec)\n}","preventionTips":["Always write listen addresses as network:address.","Validate specs at config load with a colon check.","Document the required prefix in CLI help text."],"tags":["go","sockets","address-parsing","configuration"],"backgroundTag":"invalid-socket-address","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}