{"record":{"id":"0da1b4559539ce3f","repo":"pola-rs/polars","slug":"invalid-config-file-did-you-mean-to-use-load","errorCode":null,"errorMessage":"invalid Config file (did you mean to use `load`?)\n{err}","messagePattern":"invalid Config file \\(did you mean to use `load`\\?\\)\n(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/config.py","lineNumber":447,"sourceCode":"    def load_from_file(cls, file: Path | str) -> Config:\n        \"\"\"\n        Load (and set) previously saved Config options from file.\n\n        Parameters\n        ----------\n        file : Path | str\n            File path to a JSON string produced by `Config.save()`.\n\n        See Also\n        --------\n        load : Load (and set) Config options from a JSON string.\n        save : Save the current set of Config options as a JSON string or file.\n        \"\"\"\n        try:\n            options = Path(normalize_filepath(file)).read_text()\n        except OSError as err:\n            msg = f\"invalid Config file (did you mean to use `load`?)\\n{err}\"\n            raise ValueError(msg) from err\n\n        return cls.load(options)\n\n    @classmethod\n    def restore_defaults(cls) -> type[Config]:\n        \"\"\"\n        Reset all polars Config settings to their default state.\n\n        Notes\n        -----\n        This method operates by removing all Config options from the environment,\n        and then setting any local (non-env) options back to their default value.\n\n        Examples\n        --------\n        >>> cfg = pl.Config.restore_defaults()  # doctest: +SKIP\n        \"\"\"\n        # unset all Config environment variables","sourceCodeStart":429,"sourceCodeEnd":465,"githubUrl":"https://github.com/pola-rs/polars/blob/68506541d2de983056c9eb244e1ea05fab377dfc/py-polars/src/polars/config.py#L429-L465","documentation":"`pl.Config.load_from_file(file)` normalizes the path and reads it with `Path.read_text()`; any OSError (file does not exist, permission denied, path is a directory) is re-raised as ValueError prefixed 'invalid Config file (did you mean to use `load`?)'. The hint covers the inverse mistake: passing the JSON string itself to the file-based API.","triggerScenarios":"`pl.Config.load_from_file('cfg.json')` where cfg.json does not exist or is unreadable; calling `load_from_file` with a JSON string instead of a path; a cwd-relative path resolved from the wrong working directory.","commonSituations":"Typo'd or relative config paths in scripts/notebooks; permission issues on shared or mounted config files; mixing up the argument of `load` vs `load_from_file`.","solutions":["Verify the path: `from pathlib import Path; p = Path(file).resolve(); assert p.is_file()` and fix cwd-relative paths.","If you actually have a JSON string, call `pl.Config.load(cfg_string)` instead.","Check file permissions on the config file."],"exampleFix":"# before\npl.Config.load_from_file(\"~/settings/polars.json\")  # '~' not expanded, file unreadable\n\n# after\nfrom pathlib import Path\npl.Config.load_from_file(Path(\"~/settings/polars.json\").expanduser())","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef load_config_file(file: str | Path) -> None:\n    path = Path(file).expanduser().resolve()\n    if not path.is_file():\n        raise FileNotFoundError(f\"config file not found: {path}\")\n    pl.Config.load_from_file(path)","typeGuard":null,"tryCatchPattern":"try:\n    pl.Config.load_from_file(path)\nexcept ValueError as err:\n    if \"did you mean to use `load`\" in str(err) and str(path).lstrip().startswith(\"{\"):\n        pl.Config.load(str(path))  # a JSON string was passed by mistake\n    else:\n        raise","preventionTips":["Resolve config paths explicitly (expanduser/resolve) instead of relying on cwd.","Fail fast on missing config files at startup rather than mid-job.","Keep Config file loading behind one wrapper so load/load_from_file mix-ups are impossible."],"tags":["config","file-io","path","polars"],"backgroundTag":"file-not-found","analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}