{"record":{"id":"9a9bba625d06ed32","repo":"unclecode/crawl4ai","slug":"c4a-script-compilation-error-script-i-1-lin","errorCode":null,"errorMessage":"C4A Script compilation error (script {i+1}):\n  Line {error.line}, Column {error.column}: {error.message}\n  Code: {error.source_line}\n  Suggestion: {error.suggestions[0].message}","messagePattern":"C4A Script compilation error \\(script (.+?)\\):\n  Line (.+?), Column (.+?): (.+?)\n  Code: (.+?)\n  Suggestion: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crawl4ai/async_configs.py","lineNumber":1981,"sourceCode":"            # Compile each script\n            compiled_js = []\n            for i, script in enumerate(scripts):\n                result = compile(script)\n                \n                if result.success:\n                    compiled_js.extend(result.js_code)\n                else:\n                    # Format error message following existing patterns\n                    error = result.first_error\n                    error_msg = (\n                        f\"C4A Script compilation error (script {i+1}):\\n\"\n                        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:","sourceCodeStart":1963,"sourceCodeEnd":1999,"githubUrl":"https://github.com/unclecode/crawl4ai/blob/7e801521428ee12509994d39151006f64055ebe3/crawl4ai/async_configs.py#L1963-L1999","documentation":"Raised when a js_source entry written in C4A script syntax (crawl4ai's JS DSL) fails to compile. The message includes script index, error line/column, the offending source line, and the first compiler suggestion. This happens during CrawlerRunConfig construction, before any browser launches.","triggerScenarios":"Including a js_source string with C4A DSL syntax that has a syntax error — wrong keyword, unbalanced brace, invalid selector expression; multiple scripts report their 1-based index.","commonSituations":"Hand-writing C4A scripts for the first time; editing a working script and introducing a typo; mixing plain JavaScript and C4A DSL syntax in one string.","solutions":["Read the reported Line/Column and Code — they pinpoint the exact offending token in your js_source entry","Apply the included Suggestion from the compiler","Verify you are using valid C4A syntax; if you meant plain JavaScript, ensure the string is not being routed through the C4A compiler (check js_source vs js_code usage)","Reproduce in isolation: compile just that script with crawl4ai.script's compiler to iterate faster"],"exampleFix":"// before\njs_source='''wait for \"#result\" then click it twice and extract title'''\n// after  (fix per reported line/column + suggestion)\njs_source='''wait for selector \"#result\"\nclick \"#result\" twice'''\n// then extract via extraction_strategy","handlingStrategy":"try-catch","validationCode":"from crawl4ai.script import compile_c4a_script  # name per your version\n\nfor i, src in enumerate(js_source_list or []):\n    result = compile_c4a_script(src)  # dry-run before building the config\n    if not result.success:\n        raise SystemExit(f\"script {i}: {result.first_error.message}\")","typeGuard":null,"tryCatchPattern":"try:\n    cfg = CrawlerRunConfig(js_source=scripts)\nexcept ValueError as e:\n    if \"compilation error\" in str(e).lower():\n        log_script_error(e); exit(2)   # authoring bug: fix the script\n    raise","preventionTips":["Dry-run compile C4A scripts in CI before deploy","Keep scripts in files and lint them in a pre-commit hook","Fix the reported line/column first; suggestions usually resolve cascades"],"tags":["c4a-script","javascript","compilation","validation"],"backgroundTag":null,"analyzedSha":"7e801521428ee12509994d39151006f64055ebe3","analyzedAt":"2026-08-14T20:46:20.673Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}