{"record":{"id":"8ec25f1bdf0a6859","repo":"microsoft/qlib","slug":"cannot-find-file","errorCode":null,"errorMessage":"Cannot find file {}","messagePattern":"Cannot find file (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/online/utils.py","lineNumber":32,"sourceCode":"from ...utils import get_next_trading_date\nfrom ...utils.pickle_utils import restricted_pickle_load\nfrom ...backtest.exchange import Exchange\n\nlog = get_module_logger(\"utils\")\n\n\ndef load_instance(file_path):\n    \"\"\"\n    load a pickle file\n        Parameter\n           file_path : string / pathlib.Path()\n                path of file to be loaded\n        :return\n            An instance loaded from file\n    \"\"\"\n    file_path = pathlib.Path(file_path)\n    if not file_path.exists():\n        raise ValueError(\"Cannot find file {}\".format(file_path))\n    with file_path.open(\"rb\") as fr:\n        instance = restricted_pickle_load(fr)\n    return instance\n\n\ndef save_instance(instance, file_path):\n    \"\"\"\n    save(dump) an instance to a pickle file\n        Parameter\n            instance :\n                data to be dumped\n            file_path : string / pathlib.Path()\n                path of file to be dumped\n    \"\"\"\n    file_path = pathlib.Path(file_path)\n    with file_path.open(\"wb\") as fr:\n        pickle.dump(instance, fr, C.dump_protocol_version)\n","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/online/utils.py#L14-L50","documentation":"Raised by load_instance in qlib/contrib/online/utils.py when the pickle file path passed in does not exist. load_instance deserializes user strategies and models for the online manager, and the user's account folder is expected to contain strategy_<id>.pickle and model_<id>.pickle; a missing file aborts the load before unpickling.","triggerScenarios":"UserManager.create_user/load_users reaching load_instance for a user folder that lacks strategy_*.pickle or model_*.pickle (deleted, never saved via save_user_data, or partially created); or any direct call to load_instance with a bad path.","commonSituations":"User data folder corrupted or incompletely written (crash between account save and pickle save); manually pruning files inside user folders; moving/renaming user directories so the constructed file name no longer matches.","solutions":["Inspect the user folder and confirm both strategy_<id>.pickle and model_<id>.pickle exist before load_users().","If pickles are missing, re-create the user via add_user (with its original config) or restore the files from backup.","Guard your wrapper: check file_path.exists() before calling load_instance and surface which file is missing."],"exampleFix":"# before\ninst = load_instance(user_path / \"strategy_u1.pickle\")  # ValueError: Cannot find file ...\n\n# after\nfp = user_path / \"strategy_u1.pickle\"\nif not fp.exists():\n    raise FileNotFoundError(f\"missing pickle: {fp}; re-add the user\")\ninst = load_instance(fp)","handlingStrategy":"validation","validationCode":"import pathlib\n\nrequired = [\n    user_path / f\"strategy_{user_id}.pickle\",\n    user_path / f\"model_{user_id}.pickle\",\n]\nmissing = [p for p in required if not p.is_file()]\nif missing:\n    raise FileNotFoundError(f\"user {user_id} incomplete, missing: {missing}\")\ninst = load_instance(required[0])","typeGuard":null,"tryCatchPattern":"try:\n    inst = load_instance(fp)\nexcept ValueError as e:\n    if \"Cannot find file\" in str(e):\n        raise FileNotFoundError(fp) from e\n    raise","preventionTips":["Validate user folders contain both pickles before load_users().","Save account, strategy and model atomically (save_user_data) so folders are never partial.","Back up user data directories; never prune individual pickle files by hand."],"tags":["qlib","online-manager","pickle","file-not-found","serialization"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}