{"record":{"id":"755f0c41f6350b9b","repo":"unclecode/crawl4ai","slug":"unknown-procedure-cmd-args-0-r","errorCode":null,"errorMessage":"Unknown procedure {cmd.args[0]!r}","messagePattern":"Unknown procedure (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crawl4ai/script/c4ai_script.py","lineNumber":612,"sourceCode":"        if cond_type == \"EXISTS\":\n            return f\"!!document.querySelector('{condition[1]}')\"\n        elif cond_type == \"NOT\":\n            # Recursively handle the negated condition\n            inner_condition = self._emit_condition(condition[1])\n            return f\"!({inner_condition})\"\n        else:  # JS condition\n            return condition[1]\n    \n    def _handle_cmd_or_proc(self, cmd):\n        \"\"\"Handle a command that might be a regular command or a procedure call\"\"\"\n        if not cmd:\n            return \"\"\n        \n        if isinstance(cmd, Cmd):\n            if cmd.op == \"CALL\":\n                # Inline the procedure\n                if cmd.args[0] not in self.procs:\n                    raise ValueError(f\"Unknown procedure {cmd.args[0]!r}\")\n                proc_body = self.procs[cmd.args[0]].body\n                return \"\\n\".join([self._emit_js(c) for c in proc_body if c.op != \"NOP\"])\n            else:\n                return self._emit_js(cmd)\n        return \"\"\n\n# --------------------------------------------------------------------------- #\n# 5. Helpers + demo\n# --------------------------------------------------------------------------- #\n\ndef compile_string(script: Union[str, List[str]], *, root: Union[pathlib.Path, None] = None) -> List[str]:\n    \"\"\"Compile C4A-Script from string or list of strings to JavaScript.\n    \n    Args:\n        script: C4A-Script as a string or list of command strings\n        root: Root directory for resolving includes (optional)\n    \n    Returns:","sourceCodeStart":594,"sourceCodeEnd":630,"githubUrl":"https://github.com/unclecode/crawl4ai/blob/7e801521428ee12509994d39151006f64055ebe3/crawl4ai/script/c4ai_script.py#L594-L630","documentation":"ValueError from the JS-emission stage (_handle_cmd_or_proc) of the C4A-Script compiler: it encounters a CALL to a procedure absent from self.procs while emitting JavaScript. This duplicates the earlier _inline_calls check as a defensive guard at emit time.","triggerScenarios":"Normally unreachable because _inline_calls already resolves or rejects every CALL — but can fire when the IR is manipulated between passes, when a Proc is added after collection, or when using the emitter on hand-constructed command lists.","commonSituations":"Programmatic use of compiler internals (building Cmd lists manually), version skew between cached/partial IR and the emitter, or subclass overrides that reorder passes.","solutions":["If writing scripts normally, fix the root cause as for any unknown procedure: define the PROC or correct its name.","Prefer the public compile_string()/compile() entry points instead of driving internal passes yourself.","If manipulating IR programmatically, run _collect_procs before _inline_calls/emit so every PROC is registered.","Ensure includes carrying PROC definitions are present in the parsed source."],"exampleFix":"# before\njs = compile_string([\"CALL 'do_thing'\"])  # ValueError: Unknown procedure 'do_thing'\n\n# after\njs = compile_string([\n    \"PROC do_thing {\",\n    \"  CLICK 'button#go'\",\n    \"}\",\n    \"CALL 'do_thing'\",\n])","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    js_lines = compile_string(script_lines, root=root)\nexcept ValueError as e:\n    if 'Unknown procedure' in str(e):\n        # define the PROC or fix its name, then recompile\n        raise","preventionTips":["Use public entry points (compile_string/compile) rather than internal passes.","If building IR programmatically, register procedures before inlining/emitting.","Keep scripts in CI-validated form so emit-time surprises can't reach production."],"tags":["c4a-script","compile","undefined-reference","internal-api"],"backgroundTag":null,"analyzedSha":"7e801521428ee12509994d39151006f64055ebe3","analyzedAt":"2026-08-14T20:46:20.673Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}