{"record":{"id":"a25578d9e1f33717","repo":"crewAIInc/crewAI","slug":"firecrawlapp-not-properly-initialized-a25578","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_scrape_website_tool/firecrawl_scrape_website_tool.py","lineNumber":109,"sourceCode":"            if click.confirm(\n                \"You are missing the 'firecrawl-py' package. Would you like to install it?\"\n            ):\n                import subprocess\n\n                subprocess.run([\"uv\", \"add\", \"firecrawl-py\"], check=True)  # noqa: S607\n                from firecrawl import (\n                    FirecrawlApp,\n                )\n            else:\n                raise ImportError(\n                    \"`firecrawl-py` package not found, please run `uv add firecrawl-py`\"\n                ) from None\n\n        self._firecrawl = FirecrawlApp(api_key=api_key)\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.scrape(url=url, **self.config)\n\n\ntry:\n    from firecrawl import FirecrawlApp  # noqa: F401\n\n    if not getattr(FirecrawlScrapeWebsiteTool, \"_model_rebuilt\", False):\n        FirecrawlScrapeWebsiteTool.model_rebuild()\n        FirecrawlScrapeWebsiteTool._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_scrape_website_tool/firecrawl_scrape_website_tool.py#L91-L123","documentation":"RuntimeError raised at the top of FirecrawlScrapeWebsiteTool._run when self._firecrawl is falsy — the FirecrawlApp client attribute was never populated. __init__ always assigns it on the success path, so this indicates the tool object reached _run without a completed initialization.","triggerScenarios":"Calling _run(url) on a tool built via __new__/model_copy or a test double that never set _firecrawl; running an instance whose __init__ raised midway and the error was swallowed.","commonSituations":"Mocked unit tests that forget to inject a client; Pydantic rebuild/copy paths that skip custom __init__; broad except blocks masking init failures.","solutions":["Create the tool through its constructor with a valid API key.","In tests, set tool._firecrawl to a mock before calling _run.","Let __init__ failures propagate instead of retaining half-initialized tools."],"exampleFix":"# before\ntool._firecrawl = None\ntool._run('https://x.com')  # RuntimeError\n\n# after\ntool = FirecrawlScrapeWebsiteTool(api_key=FIRECRAWL_API_KEY)\ntool._run('https://x.com')","handlingStrategy":"type-guard","validationCode":"if not getattr(tool, '_firecrawl', None):\n    raise RuntimeError('scrape tool lacks FirecrawlApp client')","typeGuard":"def scrape_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        raise  # rebuild the tool properly instead of retrying the broken instance","preventionTips":["Do not reuse instances whose __init__ raised; construct fresh.","Set tool._firecrawl = MagicMock() in unit tests before calling _run."],"tags":["firecrawl","initialization","defensive-check","runtime-error"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}