{"record":{"id":"bb308b82c13502e6","repo":"can1357/oh-my-pi","slug":"usageerror-line-magic-function-name-not-foun","errorCode":null,"errorMessage":"UsageError: Line magic function '%{name}' not found.","messagePattern":"UsageError: Line magic function '%(.+?)' not found\\.","errorType":"exception","errorClass":"NameError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/eval/py/runner.py","lineNumber":831,"sourceCode":"def _run_shell_body(body: str, *, shell_arg: str) -> int:\n    # stdin=DEVNULL: children must not inherit the runner's stdin, which is\n    # the host's NDJSON control channel (a reading child would steal frames,\n    # and inheriting the pipe deadlocks nested interpreters on Windows).\n    proc = subprocess.Popen(\n        [shell_arg, \"-c\", body],\n        stdin=subprocess.DEVNULL,\n        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","sourceCodeStart":813,"sourceCodeEnd":849,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/eval/py/runner.py#L813-L849","documentation":"The runner dispatches line magics by name through __omp_magic, which looks up the name in the registered line-magic table. Unknown names raise NameError formatted like IPython's UsageError: \"Line magic function '%name' not found.\" to mimic IPython behavior.","triggerScenarios":"Evaluating code that invokes %some_magic where some_magic was never registered via @line_magic in the runner — e.g. %matplotlib, %timeit, or any IPython-specific magic not implemented here.","commonSituations":"Running notebooks/code written for real IPython inside this eval runner, typos in a magic name, or assuming IPython-only magics (%,%%, ?, !) are supported.","solutions":["Check the runner's registered line magics and use an equivalent supported one","Replace unsupported IPython magics with plain Python code (e.g. time.perf_counter() instead of %timeit)","Remove or comment the magic line when porting IPython code","Register a custom magic with @line_magic if extending the runner"],"exampleFix":"// before\n%timeit compute()\n// after\nimport time\nt0 = time.perf_counter(); compute(); print(time.perf_counter() - t0)","handlingStrategy":"try-catch","validationCode":"# only invoke magics known to the runner\nKNOWN_LINE_MAGICS = {\"set_env\", \"run\", \"time\"}  # from runner docs\nif name not in KNOWN_LINE_MAGICS:\n    ...","typeGuard":null,"tryCatchPattern":"try:\n    __omp_magic(name, args)\nexcept NameError as e:\n    if \"Line magic function\" in str(e):\n        print(f\"{name!r} is not supported; use plain Python instead\")","preventionTips":["Check the runner's registered magic list before porting IPython code","Replace IPython-only magics with stdlib equivalents","Watch for typos in the magic name after %"],"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"}