{"record":{"id":"028905530638a792","repo":"can1357/oh-my-pi","slug":"usageerror-cell-magic-function-name-not-fou","errorCode":null,"errorMessage":"UsageError: Cell magic function '%%{name}' not found.","messagePattern":"UsageError: Cell magic function '%%(.+?)' not found\\.","errorType":"exception","errorClass":"NameError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/eval/py/runner.py","lineNumber":838,"sourceCode":"        stdout=subprocess.PIPE,\n        stderr=subprocess.STDOUT,\n    )\n    _stream_process_output(proc)\n    proc.wait()\n    return proc.returncode\n\n\ndef __omp_magic(name: str, args: str) -> Any:\n    fn = _LINE_MAGICS.get(name)\n    if fn is None:\n        raise NameError(f\"UsageError: Line magic function '%{name}' not found.\")\n    return fn(args)\n\n\ndef __omp_magic_cell(name: str, args: str, body: str) -> Any:\n    fn = _CELL_MAGICS.get(name)\n    if fn is None:\n        raise NameError(f\"UsageError: Cell magic function '%%{name}' not found.\")\n    return fn(args, body)\n\n\nclass _ShellResult(list):\n    \"\"\"Result of ``!cmd`` — list of stripped output lines.\"\"\"\n\n    def __init__(self, lines: list[str], returncode: int) -> None:\n        super().__init__(lines)\n        self.returncode = returncode\n\n    @property\n    def n(self) -> str:  # IPython compat\n        return \"\\n\".join(self)\n\n    @property\n    def s(self) -> str:  # IPython compat\n        return \" \".join(self)\n","sourceCodeStart":820,"sourceCodeEnd":856,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/eval/py/runner.py#L820-L856","documentation":"Cell magics (%%name) are dispatched by __omp_magic_cell against the registered cell-magic table. Unknown names raise NameError formatted like IPython's UsageError: \"Cell magic function '%%name' not found.\". Note that a magic implemented as a line magic is still unknown here — the tables are separate.","triggerScenarios":"Using %%bash, %%time, etc. when that cell magic is not registered; or using a name that exists only as a line magic; or typos in the cell-magic header line.","commonSituations":"Porting IPython notebooks that rely on cell magics this runner does not implement, writing %% instead of % (or vice versa) for an existing magic.","solutions":["Verify the magic exists as a cell magic (line and cell tables are separate)","Remove or rewrite the cell using plain Python if the magic is unsupported","Check the header line for typos — %%name must be on its own first line","Register the cell magic with @cell_magic if extending the runner"],"exampleFix":"// before\n%%capture out\nprint('hi')\n// after\ncaptured = io.StringIO()\nwith contextlib.redirect_stdout(captured):\n    print('hi')","handlingStrategy":"try-catch","validationCode":"# confirm the cell magic exists before using %%name\nKNOWN_CELL_MAGICS = {\"bash\"}  # from runner docs\nif name not in KNOWN_CELL_MAGICS:\n    ...","typeGuard":null,"tryCatchPattern":"try:\n    __omp_magic_cell(name, args, body)\nexcept NameError as e:\n    if \"Cell magic function\" in str(e):\n        print(f\"%%{name} not available; rewrite the cell in Python\")","preventionTips":["Remember line and cell magic tables are separate — %%x may not exist even if %x does","Check the first line of the cell for a typo'd %%header","Port IPython notebooks cell-by-cell, replacing unsupported magics"],"tags":["python","magic","ipython-compat"],"backgroundTag":"unknown-magic-command","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}