{"record":{"id":"bfa0d633aa7174ca","repo":"python/cpython","slug":"invalid-file-object-fd-r","errorCode":null,"errorMessage":"Invalid file object: {fd!r}","messagePattern":"Invalid file object: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Lib/asyncio/selector_events.py","lineNumber":275,"sourceCode":"                context = {\n                    'message':\n                        'Error on transport creation for incoming connection',\n                    'exception': exc,\n                }\n                if protocol is not None:\n                    context['protocol'] = protocol\n                if transport is not None:\n                    context['transport'] = transport\n                self.call_exception_handler(context)\n\n    def _ensure_fd_no_transport(self, fd):\n        fileno = fd\n        if not isinstance(fileno, int):\n            try:\n                fileno = int(fileno.fileno())\n            except (AttributeError, TypeError, ValueError):\n                # This code matches selectors._fileobj_to_fd function.\n                raise ValueError(f\"Invalid file object: {fd!r}\") from None\n        transport = self._transports.get(fileno)\n        if transport and not transport.is_closing():\n            raise RuntimeError(\n                f'File descriptor {fd!r} is used by transport '\n                f'{transport!r}')\n\n    def _add_reader(self, fd, callback, *args, context=None):\n        self._check_closed()\n        handle = events.Handle(callback, args, self, context=context)\n        key = self._selector.get_map().get(fd)\n        if key is None:\n            self._selector.register(fd, selectors.EVENT_READ,\n                                    (handle, None))\n        else:\n            mask, (reader, writer) = key.events, key.data\n            self._selector.modify(fd, mask | selectors.EVENT_READ,\n                                  (handle, writer))\n            if reader is not None:","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/asyncio/selector_events.py#L257-L293","documentation":"Error \"Invalid file object: {fd!r}\" thrown in python/cpython.","triggerScenarios":"Raised when an object without a valid fileno is registered with the selector event loop.","commonSituations":"See trigger scenarios.","solutions":["Pass a valid file object or file descriptor to add_reader()/add_writer(); ensure it has a fileno() returning a valid integer and is not closed."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}