{"record":{"id":"3ec4596334e0e852","repo":"microsoft/qlib","slug":"file-does-not-exist","errorCode":null,"errorMessage":"file \"{}\" does not exist","messagePattern":"file \"(.+?)\" does not exist","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"qlib/rl/contrib/naive_config_parser.py","lineNumber":28,"sourceCode":"from ruamel.yaml import YAML\n\nDELETE_KEY = \"_delete_\"\n\n\ndef merge_a_into_b(a: dict, b: dict) -> dict:\n    b = b.copy()\n    for k, v in a.items():\n        if isinstance(v, dict) and k in b:\n            v.pop(DELETE_KEY, False)\n            b[k] = merge_a_into_b(v, b[k])\n        else:\n            b[k] = v\n    return b\n\n\ndef check_file_exist(filename: str, msg_tmpl: str = 'file \"{}\" does not exist') -> None:\n    if not os.path.isfile(filename):\n        raise FileNotFoundError(msg_tmpl.format(filename))\n\n\ndef parse_backtest_config(path: str) -> dict:\n    abs_path = os.path.abspath(path)\n    check_file_exist(abs_path)\n\n    file_ext_name = os.path.splitext(abs_path)[1]\n    if file_ext_name not in (\".py\", \".json\", \".yaml\", \".yml\"):\n        raise IOError(\"Only py/yml/yaml/json type are supported now!\")\n\n    with tempfile.TemporaryDirectory() as tmp_config_dir:\n        with tempfile.NamedTemporaryFile(dir=tmp_config_dir, suffix=file_ext_name) as tmp_config_file:\n            if platform.system() == \"Windows\":\n                tmp_config_file.close()\n\n            tmp_config_name = os.path.basename(tmp_config_file.name)\n            shutil.copyfile(abs_path, tmp_config_file.name)\n","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/rl/contrib/naive_config_parser.py#L10-L46","documentation":"parse_backtest_config (qlib/rl/contrib/naive_config_parser.py:28) loads a qlib.rl backtest configuration from .py/.json/.yaml/.yml files. check_file_exist first resolves the path to an absolute path and raises FileNotFoundError('file \"<path>\" does not exist') when os.path.isfile is false — i.e. the file is missing, is a directory, or the path is wrong.","triggerScenarios":"Calling parse_backtest_config(path) where path points to a nonexistent file (typo, wrong working directory since the path is made absolute relative to cwd, or a directory path); passing a relative path from a different working directory.","commonSituations":"Running RL backtest examples with example config paths relative to the repo root while cwd is elsewhere; moved/renamed config files; missing 'default_config.yaml' in examples; typos in CLI arguments.","solutions":["Verify the file exists with os.path.isfile(path) before calling parse_backtest_config","Use an absolute path (e.g. Path(__file__).parent / 'config.yaml') instead of a cwd-relative path","Check for typos in the filename and ensure you are not passing a directory","Download/restore the config file if it is part of examples/data not shipped with the package"],"exampleFix":"# before\nconfig = parse_backtest_config('examples/rl/config.yaml')  # may not exist relative to cwd\n\n# after\nfrom pathlib import Path\ncfg_path = Path(__file__).resolve().parent / 'config.yaml'\nassert cfg_path.is_file(), f'missing config: {cfg_path}'\nconfig = parse_backtest_config(str(cfg_path))","handlingStrategy":"validation","validationCode":"import os\nabs_path = os.path.abspath(path)\nif not os.path.isfile(abs_path):\n    raise FileNotFoundError(f'backtest config not found: {abs_path}')","typeGuard":null,"tryCatchPattern":"try:\n    cfg = parse_backtest_config(path)\nexcept FileNotFoundError as e:\n    raise ValueError(f'check cwd={os.getcwd()} and the config path') from e","preventionTips":["Resolve config paths relative to the script file, not the shell cwd","Fail early with isfile checks in CLI wrappers"],"tags":["qlib","rl","backtest","config","file-not-found"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}