{"record":{"id":"3aa0d969455a6b1b","repo":"can1357/oh-my-pi","slug":"usage-run-path","errorCode":null,"errorMessage":"Usage: %run <path>","messagePattern":"Usage: %run <path>","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"packages/coding-agent/src/eval/py/runner.py","lineNumber":729,"sourceCode":"    _install_builtins(_STATE.user_ns)\n    _emit_status(\"reset\")\n\n\n@line_magic(\"load\")\ndef _magic_load(args: str) -> None:\n    path = Path(os.path.expanduser(args.strip()))\n    source = path.read_text(encoding=\"utf-8\")\n    _emit(\n        {\"type\": \"display\", \"id\": _CURRENT_RID.get(), \"bundle\": {\"text/plain\": source}}\n    )\n    _exec_source(source, _STATE.user_ns)\n\n\n@line_magic(\"run\")\ndef _magic_run(args: str) -> None:\n    parts = shlex.split(args) if args else []\n    if not parts:\n        raise ValueError(\"Usage: %run <path>\")\n    target = os.path.expanduser(parts[0])\n    saved_argv = sys.argv\n    try:\n        sys.argv = [target, *parts[1:]]\n        result_ns = runpy.run_path(target, run_name=\"__main__\")\n    finally:\n        sys.argv = saved_argv\n    for name, value in result_ns.items():\n        if name.startswith(\"__\"):\n            continue\n        _STATE.user_ns[name] = value\n\n\ndef _resolve_bash() -> str:\n    if os.name != \"nt\":\n        return \"/bin/bash\"\n    # Prefer Git Bash over WSL's System32 bash.exe, which runs inside a\n    # separate Linux environment and does not share the Windows filesystem","sourceCodeStart":711,"sourceCodeEnd":747,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/eval/py/runner.py#L711-L747","documentation":"The %run line magic executes a Python file via runpy.run_path with sys.argv rewritten. It requires at least a path argument; with none it raises ValueError with a usage string. The target path is expanduser'ed but not otherwise validated before running.","triggerScenarios":"Running '%run' with no arguments, or with only flags/extra args so parts[0] is empty after shlex.split — e.g. '%run' on its own line.","commonSituations":"Forgetting the script path, pasting only the args portion of a command, or an editor stripping the argument.","solutions":["Provide the script path: %run script.py","Include args after the path: %run script.py --flag value","Use ~/ prefix for home-relative paths (expanduser is applied)"],"exampleFix":"// before\n%run --verbose\n// after\n%run tools/build.py --verbose","handlingStrategy":"validation","validationCode":"if not args.strip():\n    raise ValueError(\"Usage: %run <path>\")  # check before invoking","typeGuard":null,"tryCatchPattern":"try:\n    %run script.py\nexcept ValueError as e:\n    if \"Usage: %run\" in str(e):\n        print(\"supply a script path: %run <path> [args...]\")","preventionTips":["Always pass the path first, flags after","Use os.path.expanduser-style ~/ paths when home-relative","Verify the file exists before %run to avoid runpy errors"],"tags":["python","magic","usage"],"backgroundTag":"magic-command-usage-error","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}