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

Ensure filename is shown when YAML raises an error #6139

Merged
merged 5 commits into from
Jan 24, 2024
Merged

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Jan 24, 2024

What does this implement/fix?

We were doing the file I/O ourselves. Since PyYAML gives a much better error if we let it do the I/O on the file handle (for all loaders), we pass the handle in instead. This mirrors how we load yaml in HA.

fixes esphome/issues#5423
fixes esphome/issues#5377

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable): fixes

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Example entry for config.yaml:

# Example config.yaml

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@codecov-commenter
Copy link

codecov-commenter commented Jan 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (23071e9) 53.69% compared to head (d48522d) 53.70%.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #6139      +/-   ##
==========================================
+ Coverage   53.69%   53.70%   +0.01%     
==========================================
  Files          50       50              
  Lines        9398     9403       +5     
  Branches     1652     1653       +1     
==========================================
+ Hits         5046     5050       +4     
- Misses       4053     4055       +2     
+ Partials      299      298       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bdraco bdraco marked this pull request as ready for review January 24, 2024 03:29
@bdraco bdraco requested a review from a team as a code owner January 24, 2024 03:29
Copy link
Contributor

@clydebarrow clydebarrow left a comment

Choose a reason for hiding this comment

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

LGTM, tested here with success! Also reports the correct location in the yaml file for broken lambdas.

@Unfocused
Copy link
Contributor

I just noticed your change to make the Dashboard use the C loader too:

I don't use the Dashboard much myself (and I'm even less familiar with its code), so I'm not sure if that's been affected or not. Worth checking?

@bdraco
Copy link
Member Author

bdraco commented Jan 24, 2024

It's all the same code path so if it's solved here it's solved there

Copy link
Member

@kbx81 kbx81 left a comment

Choose a reason for hiding this comment

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

LGTM, too -- thanks! 🍻

@kbx81 kbx81 merged commit 25ab6f0 into dev Jan 24, 2024
56 checks passed
@kbx81 kbx81 deleted the yaml_loader_filename branch January 24, 2024 05:11
@github-actions github-actions bot locked and limited conversation to collaborators Jan 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants