{"record":{"id":"d5ef084729a85afa","repo":"iflytek/astron-agent","slug":"can-not-find-relative-path","errorCode":null,"errorMessage":"can not find {relative_path}","messagePattern":"can not find (.+?)","errorType":"console","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"core/plugin/aitools/main.py","lineNumber":52,"sourceCode":"        new_paths_str = os.pathsep.join(new_paths)\n        if python_path:\n            os.environ[\"PYTHONPATH\"] = f\"{new_paths_str}{os.pathsep}{python_path}\"\n        else:\n            os.environ[\"PYTHONPATH\"] = new_paths_str\n        print(f\"🔧 PYTHONPATH: {os.environ['PYTHONPATH']}\")\n\n\ndef start_service() -> None:\n    \"\"\"Start FastAPI service\"\"\"\n    print(\"\\n🚀 Starting AITools service...\")\n\n    try:\n        # Start FastAPI application\n        relative_path = (Path(__file__).resolve().parent).relative_to(\n            Path.cwd()\n        ) / \"app/start_server.py\"\n        if not relative_path.exists():\n            raise FileNotFoundError(f\"can not find {relative_path}\")\n        subprocess.run([sys.executable, relative_path], check=True)\n    except subprocess.CalledProcessError as e:\n        print(f\"❌ Service startup failed: {e}\")\n        sys.exit(1)\n    except KeyboardInterrupt:\n        print(\"\\n🛑 Service stopped\")\n        sys.exit(0)\n\n\ndef main() -> None:\n    \"\"\"Main function\"\"\"\n    print(\"🌟 AITools Development Environment Launcher\")\n    print(\"=\" * 50)\n\n    # Set up Python path\n    setup_python_path()\n\n    # Load environment configuration","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/aitools/main.py#L34-L70","documentation":"start_service() computes a relative path from the current working directory to app/start_server.py and raises FileNotFoundError when that path does not exist. The launcher must be run from the aitools plugin root directory because the path is cwd-relative.","triggerScenarios":"Running `python -m ...main` or main() from any directory other than core/plugin/aitools, so (Path(__file__).parent).relative_to(Path.cwd()) resolves to a path where app/start_server.py is absent.","commonSituations":"Starting the service from the repo root instead of the plugin directory, IDE run configurations with the wrong working directory, container WORKDIR pointing elsewhere, symlinked installs.","solutions":["cd into core/plugin/aitools before launching the service.","Fix the IDE/docker working directory to core/plugin/aitools.","Check the printed path in the error to see which directory was expected.","Refactor start_service to use an absolute path derived from __file__ instead of cwd-relative resolution."],"exampleFix":"// before\nsubprocess.run([sys.executable, relative_path], check=True)\n\n// after\nabs_path = Path(__file__).resolve().parent / \"app/start_server.py\"\nsubprocess.run([sys.executable, abs_path], check=True)","handlingStrategy":"validation","validationCode":"from pathlib import Path\nstart_dir = Path('core/plugin/aitools')\nassert (start_dir / 'app/start_server.py').exists(), 'run from repo root or fix cwd'","typeGuard":"def launcher_ready() -> bool:\n    return (Path(__file__).resolve().parent / 'app/start_server.py').exists()","tryCatchPattern":"try:\n    start_service()\nexcept FileNotFoundError as e:\n    print(f'Launcher must run from the aitools plugin directory: {e}')\n    sys.exit(2)","preventionTips":["Always launch from core/plugin/aitools","Set the working directory explicitly in IDE run configs and Dockerfile WORKDIR","Prefer absolute paths built from __file__","Check the path in the error message against your cwd"],"tags":["file-not-found","working-directory","startup"],"backgroundTag":"file-not-found","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}