Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could more errors be ParseError? e.g. KeyAlreadyPresent, so as to report a line/col #202

Closed
anentropic opened this issue Jun 18, 2022 · 0 comments · Fixed by #208
Closed

Comments

@anentropic
Copy link

Poetry uses tomlkit for parsing their poetry.lock files

I recently had a merge conflict on my lock file

Poetry catches TOMLKitError and stringifies it to report their error:

Unable to read the lock file (Invalid TOML file /Users/anentropic/myproject/poetry.lock: Key "description " already exists.).

The problem for me is that the lock file is a) large and b) has a repetitive structure, so there are many objects with key "description" and finding the one with a duplicate is not so fun

I originally thought this was a Poetry problem where they could report more detail. I had a look in tomlkit src and sure enough there is a ParseError which reports the line and column number.

But it turns out my error is a KeyAlreadyPresent, which doesn't inherit from ParseError 😞 https://github.com/sdispater/tomlkit/blob/master/tomlkit/exceptions.py#L191

The error arises when reading the lock file https://github.com/python-poetry/poetry/blob/master/src/poetry/packages/locker.py#L454 so it would be lovely if this could be a ParseError so that lib can report helpful info to the user

Had a very quick look through the code and I wonder perhaps if errors like KeyAlreadyPresent could be caught e.g. here https://github.com/sdispater/tomlkit/blob/193b859d97afd703a70e76f347a3c198abc3dc74/tomlkit/parser.py#L149 and re-raised as an equivalent ParseError with position context info?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant