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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle settings.toml that ends without a newline #7381

Merged
merged 4 commits into from Dec 27, 2022

Conversation

jepler
Copy link
Member

@jepler jepler commented Dec 26, 2022

The settings.toml parser did not handle a file that ended without a trailing newline. When such a file was encountered, retrieving the value on the last line would result in the error Invalid byte 'EOF'. For values fetched automatically e.g., by web workflow this message could not be shown.

However, such files are (A) frequently produced by text editors that folks actually use and (B) are specifically permitted by the TOML spec. (so my pedantic objection that (C) such files are not valid UNIX text files doesn't matter 馃槈)

I had hoped this would help with #7380 but the reporter tested and it did not.

This PR also adds printing of the failure messages parsing values fetched automatically. This helps with web workflow (e.g., if you have the incorrect line CIRCUITPY_WIFI_SSID='example' you'll now see An error occurred while retrieving 'CIRCUITPY_WIFI_SSID': Invalid byte "'" each time the interpreter resets) however, values that are only fetched once like CIRCUITPY_RESERVED_PSRAM will probably still have their error messages hidden because they occur just once before the serial output is visible.

DOS and UNIX-style line endings are both now explicitly tested, as is a no-eof file.

As a workaround, adding a comment line as the last line of the settings.toml should let it parse the last value.

\r\n files must be working due to micropython's built in handling of
text-mode files, I didn't implement it.

\r-only (old mac text-mode files) are explicitly not supported by
the toml format.
Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not test but that's what your tests are for.

Could you use %S for that case in another PR where you made an error message into a QSTR?

@jepler
Copy link
Member Author

jepler commented Dec 26, 2022

@grbd if you can test with an artifact from this PR and let us know if the issue is fixed for you, that'd be helpful. Otherwise we'll probably merge it in the next day or so if we don't hear from you.

@Hecatron
Copy link

I just tried testing by adding a couple of newlines and comments at the bottom of settings.toml
but that didn't seem to fix it.
I'll have a go with the S3 daily firmware build once it hits there to see if it works

@jepler
Copy link
Member Author

jepler commented Dec 26, 2022

OK, I may be wrong about the cause then. I tested with a Pico W, perhaps there's a unique problem for esp32-s3 too.

@jepler jepler merged commit b0a635a into adafruit:main Dec 27, 2022
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

Successfully merging this pull request may close these issues.

None yet

3 participants