{"id":"2ab4a71669948f9f","repo":"python-poetry/poetry","slug":"invalid-toml-file-self-path-as-posix-e","errorCode":null,"errorMessage":"Invalid TOML file {self.path.as_posix()}: {e}","messagePattern":"Invalid TOML file (.+?): (.+?)","errorType":"exception","errorClass":"TOMLError","httpStatus":null,"severity":"error","filePath":"src/poetry/toml/file.py","lineNumber":34,"sourceCode":"        super().__init__(path)\n        self.__path = path\n\n    @property\n    def path(self) -> Path:\n        return self.__path\n\n    def exists(self) -> bool:\n        return self.__path.exists()\n\n    def read(self) -> TOMLDocument:\n        from tomlkit.exceptions import TOMLKitError\n\n        from poetry.toml import TOMLError\n\n        try:\n            return super().read()\n        except (ValueError, TOMLKitError) as e:\n            raise TOMLError(f\"Invalid TOML file {self.path.as_posix()}: {e}\")\n\n    def __str__(self) -> str:\n        return self.__path.as_posix()\n","sourceCodeStart":16,"sourceCodeEnd":38,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/toml/file.py#L16-L38","documentation":"TOMLFile.read wraps any tomlkit parse error (ValueError or TOMLKitError) into a TOMLError prefixed with the file path (toml/file.py:26-34). It indicates a syntax/semantic problem in the TOML — almost always pyproject.toml — such as duplicate keys, malformed tables, or invalid inline values.","triggerScenarios":"Any operation that loads pyproject.toml (poetry install/lock/add/etc.) when the file contains a TOML syntax error; calling TOMLFile(path).read() on a malformed file.","commonSituations":"Hand-editing pyproject.toml and introducing a duplicate key, unclosed string, or bad table header; a merge/CI tool wrote invalid TOML; mixed tabs/indentation issues.","solutions":["Read the specific tomlkit error appended after the file path — it names the exact parse problem.","Validate the file with a TOML linter or `python -c 'import tomlkit, pathlib; tomlkit.parse(pathlib.Path(\"pyproject.toml\").read_text())'`.","Fix the reported construct (duplicate key, bad inline table, unquoted value).","Restore from version control and re-apply changes incrementally to isolate the bad edit."],"exampleFix":"// before\n[tool.poetry.dependencies]\npython = \"^3.11\"\nrequests = \"^2.31\"\nrequests = \"^2.32\"   # duplicate key -> TOMLError\n// after\n[tool.poetry.dependencies]\npython = \"^3.11\"\nrequests = \"^2.32\"","handlingStrategy":"validation","validationCode":"import tomlkit, pathlib\nfrom poetry.toml import TOMLError\np = pathlib.Path(\"pyproject.toml\")\ntry:\n    tomlkit.parse(p.read_text())\nexcept Exception as e:\n    raise TOMLError(f\"Refusing to proceed; pyproject.toml is invalid: {e}\") from e\ndoc = TOMLFile(p).read()","typeGuard":null,"tryCatchPattern":"from poetry.toml import TOMLError\ntry:\n    doc = TOMLFile(path).read()\nexcept TOMLError as e:\n    log.error(\"%s is not valid TOML; fix the parse error before continuing\", path)\n    raise","preventionTips":["Validate pyproject.toml with a TOML linter in CI.","Avoid hand-editing nested tables; use `poetry` commands to mutate config.","Run `poetry check` to catch config issues early."],"tags":["toml","config","parse-error","pyproject"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}