can1357/oh-my-pi · error · NameError
UsageError: Cell magic function '%%{name}' not found.
Error message
UsageError: Cell magic function '%%{name}' not found. What it means
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.
Source
Thrown at packages/coding-agent/src/eval/py/runner.py:838
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
@property
def n(self) -> str: # IPython compat
return "\n".join(self)
@property
def s(self) -> str: # IPython compat
return " ".join(self)
View on GitHub (pinned to 9690622007)
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
Example fix
// before
%%capture out
print('hi')
// after
captured = io.StringIO()
with contextlib.redirect_stdout(captured):
print('hi') Defensive patterns
Strategy: try-catch
Validate before calling
# confirm the cell magic exists before using %%name
KNOWN_CELL_MAGICS = {"bash"} # from runner docs
if name not in KNOWN_CELL_MAGICS:
... Try / catch
try:
__omp_magic_cell(name, args, body)
except NameError as e:
if "Cell magic function" in str(e):
print(f"%%{name} not available; rewrite the cell in Python") Prevention
- 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
When it happens
Trigger: 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.
Common situations: Porting IPython notebooks that rely on cell magics this runner does not implement, writing %% instead of % (or vice versa) for an existing magic.
Related errors
- UsageError: Line 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/028905530638a792.
Report an issue: GitHub.