can1357/oh-my-pi · error · NameError
UsageError: Line magic function '%{name}' not found.
Error message
UsageError: Line magic function '%{name}' not found. What it means
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.
Source
Thrown at packages/coding-agent/src/eval/py/runner.py:831
def _run_shell_body(body: str, *, shell_arg: str) -> int:
# stdin=DEVNULL: children must not inherit the runner's stdin, which is
# the host's NDJSON control channel (a reading child would steal frames,
# and inheriting the pipe deadlocks nested interpreters on Windows).
proc = subprocess.Popen(
[shell_arg, "-c", body],
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
_stream_process_output(proc)
proc.wait()
return proc.returncode
def __omp_magic(name: str, args: str) -> Any:
fn = _LINE_MAGICS.get(name)
if fn is None:
raise NameError(f"UsageError: Line magic function '%{name}' not found.")
return fn(args)
def __omp_magic_cell(name: str, args: str, body: str) -> Any:
fn = _CELL_MAGICS.get(name)
if fn is None:
raise NameError(f"UsageError: Cell magic function '%%{name}' not found.")
return fn(args, body)
class _ShellResult(list):
"""Result of ``!cmd`` — list of stripped output lines."""
def __init__(self, lines: list[str], returncode: int) -> None:
super().__init__(lines)
self.returncode = returncode
@propertyView on GitHub (pinned to 9690622007)
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
Example fix
// before %timeit compute() // after import time t0 = time.perf_counter(); compute(); print(time.perf_counter() - t0)
Defensive patterns
Strategy: try-catch
Validate before calling
# only invoke magics known to the runner
KNOWN_LINE_MAGICS = {"set_env", "run", "time"} # from runner docs
if name not in KNOWN_LINE_MAGICS:
... Try / catch
try:
__omp_magic(name, args)
except NameError as e:
if "Line magic function" in str(e):
print(f"{name!r} is not supported; use plain Python instead") Prevention
- 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 %
When it happens
Trigger: 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.
Common situations: Running notebooks/code written for real IPython inside this eval runner, typos in a magic name, or assuming IPython-only magics (%,%%, ?, !) are supported.
Related errors
- UsageError: Cell magic function '%%{name}' not found.
- Usage: %set_env KEY VALUE
- Usage: %run <path>
- Command aborted
- Command timed out
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/bb308b82c13502e6.
Report an issue: GitHub.