8000
Skip to content

[config] Early termination of validation steps on error - #6837

Merged
jesserockz merged 3 commits into
esphome:devfrom
clydebarrow:macaddr
Jun 12, 2024
Merged

[config] Early termination of validation steps on error#6837
jesserockz merged 3 commits into
esphome:devfrom
clydebarrow:macaddr

Conversation

@clydebarrow
Copy link
Copy Markdown
Contributor

What does this implement/fix?

If the host: platform is used, and an invalid key is specified in the config for it, the platform never gets set and there is a subsequent exception thrown.

  File "/Users/clyde/dev/opensourceprojects/esp/esphome/esphome/core/__init__.py", line 634, in target_platform
    return self.data[KEY_CORE][KEY_TARGET_PLATFORM]
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
KeyError: 'target_platform'

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
  • host

Example entry for config.yaml:

# Example config.yaml

esphome:
  name: test

host:
  mac_addr: "62:23:45:AF:B3:DD" # should be mac_address

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:

@clydebarrow
clydebarrow requested a review from a team as a code owner May 31, 2024 00:49
@probot-esphome
Copy link
Copy Markdown

Hey there @esphome/core, mind taking a look at this pull request as it has been labeled with an integration (host) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@codecov-commenter
codecov-commenter commented May 31, 2024
Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.90%. Comparing base (4d8b5ed) to head (61bbe5b).
Report is 698 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #6837      +/-   ##
==========================================
+ Coverage   53.70%   53.90%   +0.19%     
==========================================
  Files          50       50              
  Lines        9408     9623     +215     
  Branches     1654     1698      +44     
==========================================
+ Hits         5053     5187     +134     
- Misses       4056     4112      +56     
- Partials      299      324      +25     

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

@jesserockz jesserockz left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would this not apply to all platforms? They all have this function call at the bottom

@clydebarrow
Copy link
Copy Markdown
Contributor Author

Would this not apply to all platforms? They all have this function call at the bottom

You would think so, but with esp32 a bad key is reported as expected, but not on host. It would make sense to move all of them to the top, I just didn't want to make unnecessary changes.

@clydebarrow
Copy link
Copy Markdown
Contributor Author

Would this not apply to all platforms? They all have this function call at the bottom

So the ESP32 and ESP8266 and probably the others can't have the validation function first, since those functions use data provided in the config, like the framework and board.

I'm still not 100% sure why there is a difference, but I think I got closer to the root cause - when executing a sequence of validation steps, an error in any step should terminate the process, since subsequent validations may depend on successful earlier ones.

Code updated accordingly. See what you think.

@clydebarrow clydebarrow changed the title Ensure platform is set if there are config errors in host: config [config] Early termination of validation steps on error May 31, 2024
@jesserockz
jesserockz merged commit 7c84343 into esphome:dev Jun 12, 2024
@jesserockz jesserockz mentioned this pull request Jun 12, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 14, 2024
@clydebarrow
clydebarrow deleted the macaddr branch October 13, 2024 09:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

core small-pr PR < 30 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0