{"record":{"id":"56f7b49057784924","repo":"cocoindex-io/cocoindex","slug":"application-file-path-not-found-app-target","errorCode":null,"errorMessage":"Application file path not found: {app_target}","messagePattern":"Application file path not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"python/cocoindex/user_app_loader.py","lineNumber":58,"sourceCode":"    full_module_name = \".\".join(package_parts + [module_name])\n    if root_parent not in sys.path:\n        sys.path.insert(0, root_parent)\n    try:\n        return importlib.import_module(full_module_name)\n    except ImportError as e:\n        raise Error(f\"Failed importing '{full_module_name}' from package: {e}\") from e\n\n\ndef load_user_app(app_target: str) -> types.ModuleType:\n    \"\"\"\n    Loads the user's application, which can be a file path or an installed module name.\n    Exits on failure.\n    \"\"\"\n    looks_like_path = os.sep in app_target or app_target.lower().endswith(\".py\")\n\n    if looks_like_path:\n        if not os.path.isfile(app_target):\n            raise Error(f\"Application file path not found: {app_target}\")\n        app_path = os.path.abspath(app_target)\n        app_dir = os.path.dirname(app_path)\n        # Use the file basename as the module name (e.g. main.py -> \"main\"). This\n        # matches the bare-module CLI form (`cocoindex update main`) so memo cache\n        # keys are consistent across both, and avoids triggering the user's\n        # `if __name__ == \"__main__\":` block during module loading.\n        module_name = os.path.splitext(os.path.basename(app_path))[0]\n\n        # If the file lives inside a package (directory has __init__.py),\n        # load it as a proper submodule so that relative imports work.\n        if os.path.isfile(os.path.join(app_dir, \"__init__.py\")):\n            root_parent, package_parts = _find_package_root(app_dir)\n            return _import_as_package_module(root_parent, package_parts, module_name)\n\n        if app_dir not in sys.path:\n            sys.path.insert(0, app_dir)\n        try:\n            spec = importlib.util.spec_from_file_location(module_name, app_path)","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/user_app_loader.py#L40-L76","documentation":"Raised when the application target passed to the loader looks like a path (contains a path separator or ends in `.py`) but no file exists at that location. The loader distinguishes file-path targets from dotted module names with this heuristic and refuses to proceed for a nonexistent file.","triggerScenarios":"Running e.g. `cocoindex update ./main.py` or `cocoindex update app/main.py` from a directory where that file does not exist, or with a typo in the path.","commonSituations":"Running the CLI from the wrong working directory; typos in the filename; assuming relative paths resolve from the project root when the CLI resolves them from cwd; deleted or moved app file.","solutions":["Run the CLI from the directory containing the app file, or pass an absolute path.","Check the path for typos and confirm the file exists (`ls`/`test -f <path>`).","If you meant an installed module, drop the path-like form and use the dotted module name (no `/` or `.py`)."],"exampleFix":"// before\ncocoindex update ./src/main.py   # run from repo root, file is at ./app/main.py\n// after\ncocoindex update ./app/main.py","handlingStrategy":"validation","validationCode":"import os\nif os.sep in target or target.lower().endswith(\".py\"):\n    assert os.path.isfile(target), f\"app file not found: {os.path.abspath(target)}\"","typeGuard":null,"tryCatchPattern":"try:\n    app = cocoindex.user_app_loader.load_user_app(app_target)\nexcept cocoindex.Error as e:\n    if 'file path not found' in str(e):\n        print(f'Check the path; cwd={os.getcwd()}'); sys.exit(1)\n    raise","preventionTips":["Run the CLI from the directory containing the app file, or use absolute paths.","Verify the file exists before invoking the CLI.","Use dotted module names for installed packages instead of paths."],"tags":["python","cli","file-not-found","app-loading"],"backgroundTag":"file-not-found","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}