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

TOML file: crash when given keyword misses quotes #313

Open
FransRoelofsen opened this issue Jul 11, 2024 · 3 comments
Open

TOML file: crash when given keyword misses quotes #313

FransRoelofsen opened this issue Jul 11, 2024 · 3 comments

Comments

@FransRoelofsen
Copy link

The TOML file contains several keywords, for instance "dll". These keywords expect a reference to a file. In case such a fille name doesn't contain spaces, users might give an unquoted line, like dll = \path\to\MetaSWAP.dll
However, this causes a crash and a message "Invalid value (at line 10, column 7)."
I found out that the TOML must contain a "python linke" string, so always including quotes. That is not clear for a user.

Suggestion: build in a check for a string value and if not present, please close the program with a clear message about this string requirement.

@Huite
Copy link
Contributor

Huite commented Jul 11, 2024

This is arguably a failure of the TOML parser; it could give a more meaningful error. But that's an upstream issue.

See:
python/cpython#115516

One possible solution is catching this error and wrapping it. I'm not sure that a very sustainable solution: we use TOML everywhere, and I don't think we would want error wrapping everywhere.

To be fair, the "invalid value" error is not that bad; the phrasing is too terse, and ideally it should mention the key, maybe mention that types matter, and not just the line number. It's just that people will see a configuration file, think "I get it", not read any specification and then get unpleasantly surprised when they got something as simple as a config file wrong.

@Huite
Copy link
Contributor

Huite commented Jul 11, 2024

For comparison, the JSON parser doesn't give a lot more info either.

JSON keys need to be quoted too, error's okay:

In [11]: json.loads('{stuff: stuff}')
JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

But if you screw up the value:

json.loads('{"stuff": stuff}')
JSONDecodeError: Expecting value: line 1 column 11 (char 10)

It's pretty much the tomllib error.

@Huite
Copy link
Contributor

Huite commented Jul 11, 2024

@FransRoelofsen, how did you make the TOML file?

As @HendrikKok mentioned, most of the time the TOML file will be generated by Python as well.
Did you take an example and copy-pasted a new path, deleting quotes that were there before? Or is the example incorrect too?

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

No branches or pull requests

2 participants