{"record":{"id":"e38643fefc49b7af","repo":"unclecode/crawl4ai","slug":"failed-to-compile-c4a-script-str-e","errorCode":null,"errorMessage":"Failed to compile C4A script: {str(e)}","messagePattern":"Failed to compile C4A script: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crawl4ai/async_configs.py","lineNumber":1993,"sourceCode":"                        f\"  Line {error.line}, Column {error.column}: {error.message}\\n\"\n                        f\"  Code: {error.source_line}\"\n                    )\n                    if error.suggestions:\n                        error_msg += f\"\\n  Suggestion: {error.suggestions[0].message}\"\n                        \n                    raise ValueError(error_msg)\n                    \n            self.js_code = compiled_js\n            \n        except ImportError:\n            raise ValueError(\n                \"C4A script compiler not available. \"\n                \"Please ensure crawl4ai.script module is properly installed.\"\n            )\n        except Exception as e:\n            # Re-raise with context\n            if \"compilation error\" not in str(e).lower():\n                raise ValueError(f\"Failed to compile C4A script: {str(e)}\")\n            raise\n    \n    def is_match(self, url: str) -> bool:\n        \"\"\"Check if this config matches the given URL.\n        \n        Args:\n            url: The URL to check against this config's matcher\n            \n        Returns:\n            bool: True if this config should be used for the URL or if no matcher is set.\n        \"\"\"\n        if self.url_matcher is None:\n            return True\n            \n        if callable(self.url_matcher):\n            # Single function matcher\n            return self.url_matcher(url)\n        ","sourceCodeStart":1975,"sourceCodeEnd":2011,"githubUrl":"https://github.com/unclecode/crawl4ai/blob/7e801521428ee12509994d39151006f64055ebe3/crawl4ai/async_configs.py#L1975-L2011","documentation":"Catch-all raised when compiling a js_source C4A script raises an unexpected exception that is not an ImportError and does not already look like a compilation error. The original exception text is embedded so the real cause (often a bug in the compiler or malformed input of an unexpected kind) is preserved.","triggerScenarios":"Passing a non-string js_source entry (None, bytes, a Path); a version mismatch between crawl4ai core and crawl4ai.script internals; any runtime error inside the compiler itself.","commonSituations":"Reading scripts from files and passing Path objects; mixing crawl4ai package versions in one environment after a partial upgrade.","solutions":["Read the embedded {str(e)} — it names the underlying failure","Ensure each js_source entry is a str (wrap Path reads: path.read_text())","Align versions: pip install --upgrade crawl4ai so core and script module match","If the error is a compiler bug, minimize the script and report it upstream"],"exampleFix":"// before\njs_source=[Path(\"scripts/scroll.c4a\")]  # Path object\n// after\njs_source=[Path(\"scripts/scroll.c4a\").read_text()]","handlingStrategy":"validation","validationCode":"js_source = [s.read_text() if isinstance(s, Path) else s for s in js_source_list]\nassert all(isinstance(s, str) and s for s in js_source)","typeGuard":"def valid_js_source(scripts) -> bool:\n    return all(isinstance(s, str) and s.strip() for s in scripts or [])","tryCatchPattern":"try:\n    cfg = CrawlerRunConfig(js_source=scripts)\nexcept ValueError as e:\n    if \"Failed to compile C4A script\" in str(e):\n        raise RuntimeError(f\"C4A compiler failure: {e}\") from e\n    raise","preventionTips":["Path.read_text() before passing file-based scripts","Keep crawl4ai core and script module versions in sync","Log the embedded inner exception text verbatim"],"tags":["c4a-script","compilation","type-error","wrapping"],"backgroundTag":null,"analyzedSha":"7e801521428ee12509994d39151006f64055ebe3","analyzedAt":"2026-08-14T20:46:20.673Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}