{"record":{"id":"b55d6f3ac77e2207","repo":"D4Vinci/Scrapling","slug":"no-sessions-registered","errorCode":null,"errorMessage":"No sessions registered","messagePattern":"No sessions registered","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"scrapling/spiders/session.py","lineNumber":70,"sourceCode":"\n        :param session_id: ID of session to remove\n        \"\"\"\n        if session_id not in self._sessions:\n            raise KeyError(f\"Session '{session_id}' not found\")\n\n        session = self._sessions.pop(session_id)\n        if session_id in self._lazy_sessions:\n            self._lazy_sessions.remove(session_id)\n\n        if session and self._default_session_id == session_id:\n            self._default_session_id = next(iter(self._sessions), None)\n\n        return session\n\n    @property\n    def default_session_id(self) -> str:\n        if self._default_session_id is None:\n            raise RuntimeError(\"No sessions registered\")\n        return self._default_session_id\n\n    @property\n    def session_ids(self) -> list[str]:\n        return list(self._sessions.keys())\n\n    def get(self, session_id: str) -> Session:\n        if session_id not in self._sessions:\n            available = \", \".join(self._sessions.keys())\n            raise KeyError(f\"Session '{session_id}' not found. Available: {available}\")\n        return self._sessions[session_id]\n\n    async def start(self) -> None:\n        \"\"\"Start all sessions that aren't already alive.\"\"\"\n        if self._started:\n            return\n\n        for sid, session in self._sessions.items():","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/D4Vinci/Scrapling/blob/5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f/scrapling/spiders/session.py#L52-L88","documentation":"The default_session_id property raises RuntimeError when no session has ever been registered. The manager promotes the first added session to default automatically, so hitting this means the SessionManager is empty — typically the spider started making requests before any session was configured.","triggerScenarios":"Accessing manager.default_session_id, or issuing a request without an explicit session, on a SessionManager where add() was never called (or every session was popped).","commonSituations":"Forgetting to configure sessions in spider setup; popping the last session during dynamic reconfiguration while requests are still in flight; constructor code that adds sessions conditionally and the condition was false.","solutions":["Register at least one session during spider init: manager.add('default', my_session, default=True).","If sessions can be removed at runtime, re-register a fallback before popping the last one.","Make session-creation config unconditional or fail loudly at startup if the list is empty."],"exampleFix":"# before\nmanager = SessionManager()\nprint(manager.default_session_id)  # RuntimeError\n\n# after\nmanager.add('main', session, default=True)\nprint(manager.default_session_id)  # 'main'","handlingStrategy":"validation","validationCode":"if not manager.session_ids:\n    manager.add('default', Session(), default=True)\n\nassert manager.session_ids, 'no sessions configured before crawl start'","typeGuard":null,"tryCatchPattern":"try:\n    sid = manager.default_session_id\nexcept RuntimeError:\n    raise SystemExit('Configure at least one session before starting the spider')","preventionTips":["Register a default session unconditionally during spider init.","Fail fast at startup if the session config list is empty instead of failing per-request later."],"tags":["session","runtime-error","configuration","spider"],"backgroundTag":null,"analyzedSha":"5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f","analyzedAt":"2026-08-14T22:23:09.440Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}