{"record":{"id":"3f1233c9f8087fc9","repo":"crewAIInc/crewAI","slug":"firecrawlapp-not-properly-initialized","errorCode":null,"errorMessage":"FirecrawlApp not properly initialized","messagePattern":"FirecrawlApp not properly initialized","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/firecrawl_crawl_website_tool/firecrawl_crawl_website_tool.py","lineNumber":109,"sourceCode":"                \"You are missing the 'firecrawl-py' package. Would you like to install it?\"\n            ):\n                import subprocess\n\n                try:\n                    subprocess.run([\"uv\", \"add\", \"firecrawl-py\"], check=True)  # noqa: S607\n                    from firecrawl import FirecrawlApp\n\n                    self._firecrawl = FirecrawlApp(api_key=self.api_key)\n                except subprocess.CalledProcessError as e:\n                    raise ImportError(\"Failed to install firecrawl-py package\") from e\n            else:\n                raise ImportError(\n                    \"`firecrawl-py` package not found, please run `uv add firecrawl-py`\"\n                ) from None\n\n    def _run(self, url: str) -> Any:\n        if not self._firecrawl:\n            raise RuntimeError(\"FirecrawlApp not properly initialized\")\n\n        url = validate_url(url)\n        return self._firecrawl.crawl(url=url, poll_interval=2, **self.config)\n\n\ntry:\n    from firecrawl import FirecrawlApp  # noqa: F401\n\n    if not getattr(FirecrawlCrawlWebsiteTool, \"_model_rebuilt\", False):\n        FirecrawlCrawlWebsiteTool.model_rebuild()\n        FirecrawlCrawlWebsiteTool._model_rebuilt = True  # type: ignore[attr-defined]\nexcept ImportError:\n    pass\n","sourceCodeStart":91,"sourceCodeEnd":123,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/firecrawl_crawl_website_tool/firecrawl_crawl_website_tool.py#L91-L123","documentation":"RuntimeError raised at the top of FirecrawlCrawlWebsiteTool._run when self._firecrawl is falsy — i.e. the FirecrawlApp client was never constructed. Normally __init__ guarantees the client exists, so this fires when construction was bypassed or partially completed (mocked init, subclass skipping super().__init__, or an init path that raised after the check).","triggerScenarios":"Calling tool._run(url) on an instance created without a completed __init__ (e.g. __new__, model_copy, or a test mock that leaves _firecrawl unset/None).","commonSituations":"Unit tests with half-mocked tools; Pydantic reconstruction paths; an earlier exception during __init__ being swallowed by a broad except, leaving a half-built object that is then run.","solutions":["Construct the tool normally: FirecrawlCrawlWebsiteTool(api_key=...) so _firecrawl is set.","In tests, inject a mock: tool._firecrawl = MagicMock().","Don't swallow exceptions from __init__; a failed init should discard the instance, not leave it runnable."],"exampleFix":"# before\ntool = FirecrawlCrawlWebsiteTool.__new__(FirecrawlCrawlWebsiteTool)\ntool._run('https://x.com')  # RuntimeError\n\n# after\ntool = FirecrawlCrawlWebsiteTool(api_key=FIRECRAWL_API_KEY)\ntool._run('https://x.com')","handlingStrategy":"type-guard","validationCode":"if not getattr(tool, '_firecrawl', None):\n    raise RuntimeError('crawl tool has no FirecrawlApp client; rebuild via constructor')","typeGuard":"def crawl_tool_ready(tool) -> bool:\n    return bool(getattr(tool, '_firecrawl', None))","tryCatchPattern":"try:\n    out = tool._run(url)\nexcept RuntimeError as e:\n    if 'not properly initialized' in str(e):\n        tool = FirecrawlCrawlWebsiteTool(api_key=KEY)\n        out = tool._run(url)\n    else:\n        raise","preventionTips":["Only run tools produced by their constructors.","Inject mock clients in tests rather than leaving internals unset."],"tags":["firecrawl","initialization","defensive-check","runtime-error"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}