{"record":{"id":"85e807a0da1c11f3","repo":"kovidgoyal/kitty","slug":"not-a-valid-file-descriptor-number-v-cannot-us","errorCode":null,"errorMessage":"Not a valid file descriptor number: %#v. Cannot use: %s","messagePattern":"Not a valid file descriptor number: %#v\\. Cannot use: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/utils/sockets.go","lineNumber":44,"sourceCode":"\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)\n\t\tif !host.IsAddress() {\n\t\t\terr = fmt.Errorf(\"Not a valid IP address: %#v. Cannot use: %s\", addr, spec)\n\t\t}\n\t\treturn\n\t}\n\tif network == \"fd\" {\n\t\tfd := -1\n\t\tif fd, err = strconv.Atoi(addr); err != nil || fd < 0 {\n\t\t\terr = fmt.Errorf(\"Not a valid file descriptor number: %#v. Cannot use: %s\", addr, spec)\n\t\t}\n\t\treturn\n\t}\n\terr = fmt.Errorf(\"Unknown network type: %#v in socket address: %s\", network, spec)\n\treturn\n}\n","sourceCodeStart":26,"sourceCodeEnd":51,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/tools/utils/sockets.go#L26-L51","documentation":"For network type fd:, ParseSocketAddress expects the address to be a non-negative integer file descriptor number (for socket-activation style listening on an inherited fd). If Atoi fails or the fd is negative, this error is returned.","triggerScenarios":"Specs like fd:abc, fd:-1, fd: (empty), or fd:3.5. Also fd: with whitespace or a 0x-prefixed value.","commonSituations":"Socket-activation configs where the fd number placeholder was never substituted; hand-written configs with typos; fd indexes passed as strings from env vars.","solutions":["Use a plain non-negative integer: fd:3.","Substitute the real fd number from the socket-activation environment (e.g. LISTEN_FDS_START + n).","Validate with strconv.Atoi and >= 0 before building the spec.","If you meant a path or TCP socket, use unix:/tcp: specs instead."],"exampleFix":"// before\nnet, addr, err := utils.ParseSocketAddress(\"fd:${FD}\") // FD unset\n// after\nnet, addr, err := utils.ParseSocketAddress(fmt.Sprintf(\"fd:%d\", fdNum))","handlingStrategy":"validation","validationCode":"_, addr, _ := strings.Cut(spec, \":\")\nif n, err := strconv.Atoi(addr); err != nil || n < 0 {\n    return fmt.Errorf(\"fd spec must be a non-negative integer, got %q\", addr)\n}","typeGuard":"func isNonNegInt(s string) bool {\n    n, err := strconv.Atoi(s)\n    return err == nil && n >= 0\n}","tryCatchPattern":"net, addr, err := utils.ParseSocketAddress(spec)\nif err != nil && strings.Contains(err.Error(), \"file descriptor\") {\n    spec = fmt.Sprintf(\"fd:%d\", fdNum)\n    net, addr, err = utils.ParseSocketAddress(spec)\n}","preventionTips":["Substitute real fd numbers from socket-activation env (LISTEN_FDS).","Validate fd specs with Atoi before startup.","Never leave fd placeholders like ${FD} unfilled."],"tags":["go","sockets","file-descriptor","validation"],"backgroundTag":"invalid-socket-address","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}